كتاب صلاة المسافرين وقصرها
6  
The Book of Prayer - Travellers
(31)
Chapter: The command to one who becomes sleepy while praying, or who starts to falter in his recitation of the Qur’an or statements of remembrance, to lie down or sit down until that goes away
(31)
باب أَمْرِ مَنْ نَعَسَ فِي صَلاَتِهِ أَوِ اسْتَعْجَمَ عَلَيْهِ الْقُرْآنُ أَوِ الذِّكْرُ بِأَنْ يَرْقُدَ أَوْ يَقْعُدَ حَتَّى يَذْهَبَ عَنْهُ ذَلِكَ
Sahih Muslim 784 a

Anas reported that the Messenger of Allah (ﷺ) entered the mosque (and he found) a rope tied between the two pillars; so he said:

What is this? They said: It is for Zainab. She prays and when she slackens or feels tired she holds it. Upon this he (the Holy Prophet) said: Untie it. Let one pray as long as one feels fresh but when one slackens or becomes tired one must stop it. (And in the hadith transmitted by Zuhair it is:" He should sit down." )
وَحَدَّثَنَا أَبُو بَكْرِ بْنُ أَبِي شَيْبَةَ، حَدَّثَنَا ابْنُ عُلَيَّةَ، ح وَحَدَّثَنِي زُهَيْرُ بْنُ حَرْبٍ، حَدَّثَنَا إِسْمَاعِيلُ، عَنْ عَبْدِ الْعَزِيزِ بْنِ صُهَيْبٍ، عَنْ أَنَسٍ، قَالَ دَخَلَ رَسُولُ اللَّهِ صلى الله عليه وسلم الْمَسْجِدَ وَحَبْلٌ مَمْدُودٌ بَيْنَ سَارِيَتَيْنِ فَقَالَ ‏"‏ مَا هَذَا ‏"‏ ‏.‏ قَالُوا لِزَيْنَبَ تُصَلِّي فَإِذَا كَسِلَتْ أَوْ فَتَرَتْ أَمْسَكَتْ بِهِ ‏.‏ فَقَالَ ‏"‏ حُلُّوهُ لِيُصَلِّ أَحَدُكُمْ نَشَاطَهُ فَإِذَا كَسِلَ أَوْ فَتَرَ قَعَدَ ‏"‏ ‏.‏ وَفِي حَدِيثِ زُهَيْرٍ ‏"‏ فَلْيَقْعُدْ ‏"‏ ‏.‏
Reference : Sahih Muslim 784a
In-book reference : Book 6, Hadith 259
USC-MSA web (English) reference : Book 4, Hadith 1714
  (deprecated numbering scheme)