The Messenger of Allah ﷺ said, "When you are present with someone who is sick or dying, speak only good words, for the angels say 'Amen' to whatever you say."When Abu Salama died, I went to the Prophet ﷺ and said, "Messenger of Allah, Abu Salama has died."He said, "Say, 'O Allah, forgive me and him, and grant me a good successor in his place.'"She said, "I did so, and Allah granted me one better than him, Muhammad the Messenger of Allah ﷺ."
حدثنا أبو بكر بن أبي شيبة وعلي بن محمد قالا حدثنا أبو معاوية عن الأعمش عن شقيق
قال رسول الله ﷺ إذا حضرتم المريض أو الميت فقولوا خيرا فإن الملائكة يؤمنون على ما تقولون فلما مات أبو سلمة أتيت النبي ﷺ فقلت يا رسول الله إن أبا سلمة قد مات قال قولي اللهم اغفر لي وله وأعقبني منه عقبى حسنة قالت ففعلت فأعقبني الله من هو خير منه محمد رسول الله ﷺ
Recorded by Muslim, in the Book of Funerals, Chapter on What Is Said in the Presence of the Sick and the Dead, no. 919, on the authority of Abu Bakr Ibn Abu Shayba and others, with this wording.