Hadithcore
Mishkat al-Masabih, 2382, 2383

Hudhaifa said that when the Prophet (ﷺ) lay down on his bed at night he placed his hand under his cheek, and would then say, "O God, in Your name I die and live." When he awoke he said, "Praise be to God who has given us life after causing us to die,* and to whom we shall be resurrected." *Behind this phrase probably lies the idea expressed in Qur’an, xxxix, 42 which says, "It is God who takes the souls at the time of their death, and those which do not die during their sleep." Bukhari transmitted it, Muslim transmitting from al-Bara’.

وَعَنْ حُذَيْفَةَ قَالَ: كَانَ النَّبِيُّ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ إِذَا أَخَذَ مَضْجَعَهُ مِنَ اللَّيْلِ وَضَعَ يَدَهُ تَحْتَ خَدِّهِ ثُمَّ يَقُولُ: «اللَّهُمَّ بِاسْمِكَ أَمُوتُ وَأَحْيَا» . وَإِذَا اسْتَيْقَظَ قَالَ: «الْحَمْدُ الله الَّذِي أَحْيَانًا بَعْدَمَا مَا أماتنا وَإِلَيْهِ النشور» . رَوَاهُ البُخَارِيّ وَمُسلم عَن الْبَراء

References1 variant
In-Book Reference
Book 9, Hadith 154