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."
إن رسول الله ﷺ كان يؤتى بالرجل المتوفى عليه الدين، فيسأل: هل ترك لدينه فضلا؟ فإن حدث أنه ترك لدينه وفاء صلى، وإلا قال للمسلمين: صلوا على صاحبكم فلما فتح الله عليه الفتوح قال: أنا أولى بالمؤمنين من أنفسهم، فمن توفي من المؤمنين فترك دينا فعلي قضاؤه، ومن ترك مالا فلورثته.
Bukhari narrated it in the Chapter on Suretyship (2298), and Muslim in the Chapter on Inheritance Shares (1619), both of them from the hadith of Layth, from Aqeel, from Ibn Shihab, from Abu Salama, from Abu Hurairah, and he mentioned it. Tayalisi (2338) said, "By this, those hadiths that came concerning refraining from praying over one who had a debt were abrogated."