Hazrat Anas (may Allah be pleased with him) narrated that the Messenger of Allah (peace and blessings be upon him) said: None of you should wish for death because of any harm that has befallen him. If wishing for death becomes necessary, then he should say: "O Allah, keep me alive as long as life is better for me, and cause me to die when death is better for me."
Qais bin Abi Hazim narrated that I went to the service of Hazrat Khabbab bin Arat (may Allah be pleased with him); he had applied seven cauterizations (for the treatment of some illness). He said that if the Messenger of Allah (peace and blessings be upon him) had not forbidden us from praying for death, I would certainly have prayed for it.