كتاب الذكر والدعاء والتوبة والاستغفار
48  
The Book Pertaining to the Remembrance of Allah, Supplication, Repentance and Seeking Forgiveness
(4)
Chapter: It Is Disliked To Wish For Death Because Of Some Harm That Has Befallen One
(4)
باب كَرَاهَةِ تَمَنِّي الْمَوْتِ لِضُرٍّ نَزَلَ بِهِ
Sahih Muslim 2680 a

Anas (b. Malik) reported Allah's Messenger (ﷺ) as saying. None of you should make a request for death because of the trouble in which he is involved, but if there is no other help to it, then say:

O Allah, keep me alive as long as there is goodness in life for me and bring death to me when there is goodness in death for me.
حَدَّثَنَا زُهَيْرُ بْنُ حَرْبٍ، حَدَّثَنَا إِسْمَاعِيلُ، - يَعْنِي ابْنَ عُلَيَّةَ - عَنْ عَبْدِ الْعَزِيزِ، عَنْ أَنَسٍ، قَالَ قَالَ رَسُولُ اللَّهِ صلى الله عليه وسلم ‏ "‏ لاَ يَتَمَنَّيَنَّ أَحَدُكُمُ الْمَوْتَ لِضُرٍّ نَزَلَ بِهِ فَإِنْ كَانَ لاَ بُدَّ مُتَمَنِّيًا فَلْيَقُلِ اللَّهُمَّ أَحْيِنِي مَا كَانَتِ الْحَيَاةُ خَيْرًا لِي وَتَوَفَّنِي إِذَا كَانَتِ الْوَفَاةُ خَيْرًا لِي ‏"‏ ‏.‏
Reference : Sahih Muslim 2680a
In-book reference : Book 48, Hadith 10
USC-MSA web (English) reference : Book 35, Hadith 6480
  (deprecated numbering scheme)