Abu Hurairah reported,

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

Tirmidhi 1070

Sahih

حدثني أبو الفضل مكتوم بن العباس الترمذي حدثنا عبد الله بن صالح قال حدثني الليث قال حدثني عقيل عن ابن شهاب قال أخبرني أبو سلمة بن عبد الرحمن

عن أبي هريرة

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

الترمذي 1070صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami Tirmidhi
Book
Funerals
Chapter
Prayer over one in debt
Numbering
Darussalam 1070
Tirmidhi 1070