Abu Hurairah reported,

The Messenger of Allah ﷺ used to be brought a man who had died with debt upon him, and he would ask, "Did he leave behind anything to settle his debt?" If he was told that the man had left enough to cover his debt, he would pray over him. Otherwise, he would say to the Muslims, "Pray over your companion."When Allah granted him the conquests, he said, "I am closer to the believers than they are to themselves. Whoever among the believers dies leaving a debt, its settlement is upon me, and whoever leaves wealth, it belongs to his heirs."

Azami 3751

Sahih

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

إن رسول الله ﷺ كان يؤتى بالرجل المتوفى عليه الدين، فيسأل: هل ترك لدينه فضلا؟ فإن حدث أنه ترك لدينه وفاء صلى، وإلا قال للمسلمين: صلوا على صاحبكم فلما فتح الله عليه الفتوح قال: أنا أولى بالمؤمنين من أنفسهم، فمن توفي من المؤمنين فترك دينا فعلي قضاؤه، ومن ترك مالا فلورثته.

الأعظمي 3751صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Prayer over the deceased
Section
Abrogation of not praying over one who died while owing a debt
Numbering
Jami al-Kamil 3751 (2nd edition)