كتاب الصلاة
4  
The Book of Prayers
(21)
Chapter: If The Imam Experiences An Excuse, From Illness, Or Travelling, Etc. He May Appoint Someone Else To Lead The People In Prayer; The One Who Offers Prayer Behind The Imam Sitting Because He Is Unable To Stand Must Stand If He Is Able To Do So; And The Abrogation Of Sitting Behind A Sitting Imam For Those Who Are Able To Stand
(21)
باب اسْتِخْلاَفِ الإِمَامِ إِذَا عَرَضَ لَهُ عُذْرٌ مِنْ مَرَضٍ وَسَفَرٍ وَغَيْرِهِمَا مَنْ يُصَلِّي بِالنَّاسِ وَأَنَّ مَنْ صَلَّى خَلْفَ إِمَامٍ جَالِسٍ لِعَجْزِهِ عَنِ الْقِيَامِ لَزِمَهُ الْقِيَامُ إِذَا قَدَرَ عَلَيْهِ وَنَسْخِ الْقُعُودِ خَلْفَ الْقَاعِدِ فِي حَقِّ مَنْ قَدَرَ عَلَى الْقِيَامِ
Sahih Muslim 419 a

Anas b. Malik reported, Abu Bakr led them in prayer due to the illness of the Messenger of Allah (ﷺ) of which be died. It was a Monday and they stood in rows for prayer. The Messenger of Allah (ﷺ) drew aside the curtain of ('A'isha's) apartment and looked at us while he was standing, and his (Prophet's) face was (as bright) as the paper of the Holy Book. The Messenger of Allah (ﷺ) felt happy and smiled. And we were confounded with joy while in prayer due to the arrival (among our midst) of the Messenger of Allah (ﷺ), Abu Bakr stepped back upon his heels to say prayer in a row perceiving that the Messenger of Allah (ﷺ) had come out for prayer. The Messenger of Allah (ﷺ) with the help of his hand signed to them to complete their prayer. The Messenger of Allah (ﷺ) went back (to his apartment) and drew the curtain. He (the narrator) said:

The Messenger of Allah (ﷺ) breathed his last on that very day.
حَدَّثَنِي عَمْرٌو النَّاقِدُ، وَحَسَنٌ الْحُلْوَانِيُّ، وَعَبْدُ بْنُ حُمَيْدٍ، - قَالَ عَبْدٌ أَخْبَرَنِي وَقَالَ الآخَرَانِ، حَدَّثَنَا يَعْقُوبُ، - وَهُوَ ابْنُ إِبْرَاهِيمَ بْنِ سَعْدٍ - وَحَدَّثَنِي أَبِي، عَنْ صَالِحٍ، عَنِ ابْنِ شِهَابٍ، قَالَ أَخْبَرَنِي أَنَسُ بْنُ مَالِكٍ، أَنَّ أَبَا بَكْرٍ، كَانَ يُصَلِّي لَهُمْ فِي وَجَعِ رَسُولِ اللَّهِ صلى الله عليه وسلم الَّذِي تُوُفِّيَ فِيهِ حَتَّى إِذَا كَانَ يَوْمُ الاِثْنَيْنِ - وَهُمْ صُفُوفٌ فِي الصَّلاَةِ - كَشَفَ رَسُولُ اللَّهِ صلى الله عليه وسلم سِتْرَ الْحُجْرَةِ فَنَظَرَ إِلَيْنَا وَهُوَ قَائِمٌ كَأَنَّ وَجْهَهُ وَرَقَةُ مُصْحَفٍ ‏.‏ ثُمَّ تَبَسَّمَ رَسُولُ اللَّهِ صلى الله عليه وسلم ضَاحِكًا - قَالَ - فَبُهِتْنَا وَنَحْنُ فِي الصَّلاَةِ مِنْ فَرَحٍ بِخُرُوجِ رَسُولِ اللَّهِ صلى الله عليه وسلم وَنَكَصَ أَبُو بَكْرٍ عَلَى عَقِبَيْهِ لِيَصِلَ الصَّفَّ وَظَنَّ أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم خَارِجٌ لِلصَّلاَةِ فَأَشَارَ إِلَيْهِمْ رَسُولُ اللَّهِ صلى الله عليه وسلم بِيَدِهِ أَنْ أَتِمُّوا صَلاَتَكُمْ - قَالَ - ثُمَّ دَخَلَ رَسُولُ اللَّهِ صلى الله عليه وسلم فَأَرْخَى السِّتْرَ - قَالَ - فَتُوُفِّيَ رَسُولُ اللَّهِ صلى الله عليه وسلم مِنْ يَوْمِهِ ذَلِكَ ‏.‏
Reference : Sahih Muslim 419a
In-book reference : Book 4, Hadith 106
USC-MSA web (English) reference : Book 4, Hadith 840
  (deprecated numbering scheme)