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."
حدثنا يزيد أخبرنا ابن أبي ذئب عن الزهري عن أبي سلمة
كان رسول الله ﷺ إذا شهد جنازة سأل هل على صاحبكم دين فإن قالوا نعم قال هل له وفاء فإن قالوا نعم صلى عليه وإن قالوا لا قال صلوا على صاحبكم فلما فتح الله عز وجل عليه الفتوح قال أنا أولى بالمؤمنين من أنفسهم فمن ترك دينا فعلي ومن ترك مالا فلورثته
Its chain of transmission is sahih. Muslim narrated it, 2:5, with several chains, among them the narration of Ibn Numayr from Ibn Abu Dhib, from Zuhri, with this same chain, though he did not mention its wording, referring instead to the narration before it. Bukhari narrated it, 4:390, 9:451, and Tirmidhi, 2:162, both of them by way of Layth from Aqeel, from Zuhri, with it. Muslim also narrated it by way of Layth, among the chains we referred to. It will come again in the Musnad at 9847 by way of Layth. Muslim also narrated it, giving its wording at 2:4–5, by way of Yunus from Zuhri. It will come again in abridged form at 8937 and 9184, from the narration of Amash from Abu Salih, from Abu Hurairah, and its ending has already passed with the same meaning at 7848, from the narration of Muhammad bin Amr from Abu Salama.