Sayyiduna Abu Hurairah (may Allah be pleased with him) narrates: When the dead body of a person who was in debt was brought to the service of the Prophet (peace and blessings be upon him), he would ask whether the deceased had left anything for the repayment of his debt. If it was informed that he had left something through which his debt could be paid, the Prophet (peace and blessings be upon him) would perform his funeral prayer. Otherwise, he (peace and blessings be upon him) would say, "You people perform the funeral prayer of your companion." When Allah Almighty granted victories to the Prophet (peace and blessings be upon him), he said: "I am closer to every believer than his own self. Whoever dies in a state that he owes a debt, its payment is my responsibility, and whoever leaves wealth, it will go to his heirs."
Hadith Referenceصحیح ابن حبان / كتاب السير / 4854
Hadith Gradingفضيلة الشيخ الإمام محمد ناصر الدين الألبانيصحيح - «أحكام الجنائز» (103 و 110)، «الإرواء» (5/ 249).فضيلة الشيخ العلّامة شُعيب الأرناؤوطإسناده صحيح على شرط مسلم