Anas bin Malik reported,

The Messenger of Allah ﷺ said, "Let none of you wish for death because of some hardship that has befallen him. If one must wish for death, let him say, 'O Allah, keep me alive as long as life is better for me, and take me when death is better for me.'"

Azami 3526

Sahih

عن أنس بن مالك قال

قال رسول الله ﷺ: لا يتمنين أحد منكم الموت لضر نزل به، فإن كان لابد متمنيا للموت فليقل: اللهم أحيني ما كانت الحياة خيرا لي، وتوفني إذا كانت الوفاة خيرا لي.

الأعظمي 3526صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Dying person
Section
Disliking wishing for death
Numbering
Jami al-Kamil 3526 (2nd edition)
Azami 3526