The Messenger of Allah ﷺ used to be brought a deceased man who owed a debt. He would ask, "Did he leave anything to settle his debt?" If he was told that the man had left enough to repay it, he would pray over him. Otherwise, he would say, "Pray over your companion yourselves."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 is upon me, and whoever leaves wealth, it belongs to his heirs."
أن رسول الله ﷺ كان يؤتى بالرجل الميت عليه الدين، فيسأل: هل ترك لدينه من قضاء؟ فإن حدث أنه ترك وفاء صلى عليه، وإلا قال: صلوا على صاحبكم. فلما فتح الله عليه الفتوح قال: أنا أولى بالمؤمنين من أنفسهم، فمن توفي وعليه دين فعلي قضاؤه، ومن ترك مالا فهو لورثته.
Reported by Bukhari in the Book of Suretyship (2298), and Muslim in the Book of Inheritance Shares (1619), both from the hadith of Layth, from Aqeel, from Ibn Shihab, from Abu Salama, from Abu Hurairah, who mentioned it.His statement, "to his heirs," is more precise than what others have said, and in another narration it reads "to his agnate relatives." These come either after the holders of fixed shares, or after what remains once the holders of fixed shares have taken their portions. So the meaning of the hadith is that this applies after the heirs, or that the heirs are meant along with the agnate relatives, in the case that something remains after the holders of fixed shares.