Praise be to Allah, and may peace and blessings be upon the Messenger of Allah. To proceed:
It is not permissible for a believer to wish for death because of the harm, distress, or problems that befall him in this worldly life. The Prophet ﷺ prohibited this, saying: “None of you should wish for death because of a harm that has afflicted him.”
If a person's affliction becomes severe and he is unable to ward it off, then he should make the supplication that the Prophet ﷺ taught:
“O Allah, keep me alive as long as life is better for me, and cause me to die when death is better for me.”
This supplication entrusts the matter to Allah تعالى and makes the believer content with what Allah chooses for him, knowing that his life and death are in Allah’s hands, and that Allah knows best what is good for him.
And Allah تعالى knows best.