WE RELATE FROM the Ṣaḥīḥs of al-Bukhārī and Muslim from Anas
who reported that the Messenger of Allah
said: “None of you should hope for death because of some harm that has befallen him. If he has no other resort then let him say: O Allah, let me live as long as living is better for me, and cause me to die when dying is better for me.” [1].
Allāhumma aḥyinī mā kānati-l-ḥayātu khayran lī, wa tawaffanī idhā kānati-l-wafātu khayran lī.
The ‘ulamā’ from among our colleagues and others have stated that this may be said when someone hopes for death to avoid harm, or something like that. If one hopes for death out of fear for his religion because of the corruption of the times and the like, that is not makrūh.
References
[1] Al-Bukhārī (5671), Muslim (2680), Abū Dāwūd (3108), at-Tirmidhī (971) an-Nasā’ī (4/3).