The Messenger of Allah ﷺ said, "None of you should wish for death or pray for it before it comes to him, unless he is certain of his own deeds. For if one of you dies, his deeds come to an end, and a believer's life only adds to his good."
وبإسناده عن رسول الله ﷺ قال لا يتمنى أحدكم الموت ولا يدعو به من قبل أن يأتيه إلا أن يكون قد وثق بعمله فإنه إن مات أحدكم انقطع عنه عمله وإنه لا يزيد المؤمن عمره إلا خيرا
Its chain of transmission is sahih. Suyuti narrated something similar in wording, "None of you should wish for death, whether he is a doer of good, for he may increase it, or a doer of evil, for he may repent." Bukhari and Tirmidhi narrated it from Abu Hurairah, and Suyuti marked it as sahih.