The Messenger of Allah ﷺ said, "Satan ties three knots at the back of the head of each one of you when he sleeps at night, securing each knot with the words, 'You have a long night ahead, so sleep on.' If he wakes up and remembers Allah, one knot is loosened. If he performs ablution, another knot is loosened. And if he prays, all the knots are loosened, so he begins his morning energetic and in good spirits, having attained good. Otherwise, he begins his morning sluggish and in foul spirits, having attained no good."
حدثنا أبو بكر بن أبي شيبة حدثنا أبو معاوية عن الأعمش عن أبي صالح
قال رسول الله ﷺ يعقد الشيطان على قافية رأس أحدكم بالليل بحبل فيه ثلاث عقد فإن استيقظ فذكر الله انحلت عقدة فإذا قام فتوضأ انحلت عقدة فإذا قام إلى الصلاة انحلت عقده كلها فيصبح نشيطا طيب النفس قد أصاب خيرا وإن لم يفعل أصبح كسلا خبيث النفس لم يصب خيرا
[Sahih]. Ahmad narrated it in 2:253, from Abu Muawiya, who said, "Amash narrated it to us," with the same wording, and it has corroborating narrations elsewhere, hadith no. 1142. Muslim also narrated it, in the Book of Prayer, Tahajjud, chapter on the devil tying a knot at the back of the head, travelers, chapter on encouraging night prayer even if it is little, hadith no. 776, and others narrated it as well, from the hadith of Abu Hurairah with the same wording.