It is makruh or “disliked” to wish for one’s death, or pray to Allah for it, due to poverty, distress, illness, or the like. The six canonical compilers of hadith narrate on the authority of Anas that the Prophet, peace be upon him, said: “Let no one among you wish for death due to any hardship that may befall him. But if one has no other choice, but to do so, one should say: “O Allah! Grant me life as long as life is good for me, and cause me to die when death is better for me.”
The wisdom in the prohibition against wishing for death becomes obvious from a hadith narrated by Umm al-Fadl: “The Prophet, peace be upon him, went to see Al-‘Abbas. He found him wishing for death. Thereupon the Prophet said: ‘O Abbas! O Uncle of Allah’s Messenger! Do not wish for death. If you do good and live long, your good deeds will multiply. Then that is better for you. If you are not good and your death is delayed, you may seek Allah’s forgiveness. That is better for you. So do not wish for death’.” (Narrated by Ahmad and Al-Hakim, who says it is sound according to Muslim’s criteria)
It is permissible, however, to wish for death, and there is no harm in doing so, when one fears persecution that puts one’s faith at risk, as is indicated by the following supplication of the Messenger of Allah, peace be upon him: Allahumma inni as’aluka fi’lal khairat wa tarkal munkarat wa hubbal masakin wa an taghfarali wa tarhamani wa izha aradata fitnatan fi qaumi fatawafani ghaira maftunin wa as’aluka hubbaka wa hubba man yuhibbuka wa hubba ‘amalin yuqaribu ila hubbikaÂ “O Allah! I ask You for the means to do good, to avoid evil, and to love the poor, and I beseech You to forgive me and have mercy on me. When You subject my people to a trial, cause me to die without being affected by it. O Allah! I ask Your love, the love of those who love You, and the love of all such actions that bring one closer to Your Love.”(Narrated by Tirmizhi who said it is a good and sound hadith)
‘Umar used to pray in these words: Allahumma kabirat sinni wa da’ufat quwwati wa anshrat ra’i-atifaqbidni ilaika ghaira mudayi’ wa la mufaratti “O Allah! I have grown old, I have become weak, and my flock has spread far and wide. Therefore, O Allah, take me to You before I fall short of doing my duties or transgress my limits.” This is reported by Malik.