Abu Hurairah reported,

Whenever the Messenger of Allah ﷺ attended a funeral, he would ask, "Did your companion owe any debt?"If they replied, "Yes," he would ask, "Did he leave behind enough to repay it?"If they said, "Yes," he would pray over him. But if they said, "No," he would tell them, "Pray over your companion yourselves."Then, when Allah عز وجل granted him the conquests, he said, "I am closer to the believers than they are to themselves. Whoever dies leaving a debt, its repayment falls upon me, and whoever leaves wealth behind, it belongs to his heirs."

Ahmad 7899

Sahih

حدثنا يزيد أخبرنا ابن أبي ذئب عن الزهري عن أبي سلمة

عن أبي هريرة قال

كان رسول الله ﷺ إذا شهد جنازة سأل هل على صاحبكم دين فإن قالوا نعم قال هل له وفاء فإن قالوا نعم صلى عليه وإن قالوا لا قال صلوا على صاحبكم فلما فتح الله عز وجل عليه الفتوح قال أنا أولى بالمؤمنين من أنفسهم فمن ترك دينا فعلي ومن ترك مالا فلورثته

أحمد 7899صحيح
Contents
Reference
Commentary
Ayat
Collection
Musnad Ahmad
Book
Abu Hurairah
Numbering
Darussalam 7899
Ahmad 7899