I heard the Messenger of Allah ﷺ say, "When one of you becomes drowsy while in the mosque, let him move from his seat to another."
حدثنا هناد بن السري عن عبدة عن ابن إسحق عن نافع
سمعت رسول الله ﷺ يقول إذا نعس أحدكم وهو في المسجد فليتحول من مجلسه ذلك إلى غيره
Its isnad is hasan. Tirmidhi transmitted it in the chapter on prayer, in the section on one who dozes on Friday and moves from his seat, hadith 526, from the hadith of Abdah bin Sulayman with this wording, and he said, hasan sahih. Ibn Khuzayma graded it sahih, hadith 1819, as did Ibn Hibban, hadith 571, and Hakim according to the standard of Muslim, 1/291, and Dhahabi agreed with him.