Whenever the Messenger of Allah ﷺ intended to sleep, he would say, "Allah, in Your name I die and I live." And when he woke, he would say, "Praise be to Allah who has restored my soul to me after causing it to die, and to Him is the resurrection."
حدثنا عمر بن إسمعيل بن مجالد بن سعيد الهمداني حدثنا أبي عن عبد الملك بن عمير عن ربعي
أن رسول الله ﷺ كان إذا أراد أن ينام قال اللهم باسمك أموت وأحيا وإذا استيقظ قال الحمد لله الذي أحيا نفسي بعد ما أماتها وإليه النشور
Bukhari also narrated it in the Book of Supplications, chapter on what one says when going to sleep, no. 6312, from the hadith of Abdul-Malik bin Umayr through the same route.