Whenever a funeral procession was brought to the Messenger of Allah ﷺ or passed by him, he would ask, "Did he leave behind any debt?"If they said yes, he would ask, "Did he leave behind enough to settle it?"If they said yes, he would pray over him. But if they said no, he would say, "Pray over your companion yourselves."
حدثنا معاوية قال حدثنا أبو إسحاق عن الأعمش عن أبي صالح
كان رسول الله ﷺ إذا أتي أو مر عليه بجنازة سألهم هل ترك دينا فإن قالوا نعم قال هل ترك وفاء فإن قالوا نعم صلى عليه وإن قالوا لا قال صلوا على صاحبكم
Its isnad is sahih. It was mentioned previously at 2/990 of the printed edition. The hadith was narrated by Bukhari 3/128, in the chapter on suretyship, section on debt, and Muslim in the chapter on inheritance shares, section on whoever leaves wealth it goes to his heirs, 3/1237 no. 1619, and Tirmidhi 3/373 no. 1070, in the chapter on funerals, section on the funeral prayer over one who owed a debt, and Nasai 4/66, in the chapter on funerals, section on the funeral prayer over one who has a debt owed by him, and Ibn Majah 2145, and Ibn Abu Shayba 3/371.