All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah and that Muhammad, sallallaahu ʻalayhi wa sallam, is His slave and Messenger.
It is prescribed for the sick person to supplicate Allaah, The Exalted, to bless him with recovery, as reported in the authentic ahaadeeth. He should not supplicate Allaah to cause him to die, nor should his supplications imply wishing to die, or pessimism, or despair of the mercy of Allaah. The Prophet, sallallaahu ʻalayhi wa sallam, used to implore Allaah to bless the sick with recovery, as reported in the hadeeth narrated by ʻAa'ishah ; when the Prophet, sallallaahu ʻalayhi wa sallam, came to a sick person, he would make supplication for him and say, ‘Athhib al-baas, Rabba an-naas, washfi Anta Ash-Shaafi, laa shifaa’a illa shifaa’uka, shifaa’an la yughadiru saqama.’ (O Allaah; take away the pain, O Lord of mankind, and grant healing, for You are the Healer, and there is no healing but Your healing that leaves no trace of sickness.)” [Al-Bukhari and Muslim]
Moreover, it has been narrated on the authority of ʻAli ibn Abi Taalib that he said:
“I was ill and the Messenger of Allaah, sallallaahu ʻalayhi wa sallam, passed by me while I was saying, ‘O Allaah, if my time has come (to die), then give me relief, and if it is not due yet, then make my life more bountiful, and if it is a trial, then grant me patience.' The Messenger of Allaah, sallallaahu ʻalayhi wa sallam, said, ‘What did you say?’” He repeated to him what he said. He (one of the narrators) said, “So he, sallallaahu ʻalayhi wa sallam, struck him with his foot and said, ‘O Allaah, grant him well-being, or grant him recovery' He ('Ali) said, ‘I did not suffer from my ailment again...’” [Ahmad and At-Tirmithi]
It is prescribed for the sick person to implore Allaah for recovery; however, if his illness gets worse and his burden becomes so hard for him to bear that he wishes to die, then he may recite the supplication reported in the following hadeeth:
Anas ibn Maalik reported that the Prophet, sallallaahu ʻalayhi wa sallam, said, “None of you should wish for death because of a calamity befalling him; but if he has to wish for death, then he should say, ‘Allaahumma ahyini ma kaanat al-hayaatu khayran li, watawaffani ithaa kaanat al-wafaatu kharyran li.’ (Which means: O Allaah! Keep me alive as long as life is better for me, and cause me to die if death is better for me.)” [Al-Bukhari and Muslim]
Allaah knows best.