Sayyiduna Abu Hurairah, may Allah be pleased with him, narrates: In the blessed time of the Prophet Muhammad, peace and blessings be upon him, when a person would pass away and he had a debt, the Prophet, peace and blessings be upon him, would ask whether he had left anything for the repayment of the debt. If it was told to him, "Yes," then the Prophet, peace and blessings be upon him, would perform his funeral prayer. And if it was told to him, "No," then the Prophet, peace and blessings be upon him, would say, "You people perform the funeral prayer of your companion." When Allah Almighty granted His Messenger, peace and blessings be upon him, victories, he said: "I am closer to the believers than their own selves. Whoever leaves behind a debt, its repayment is my responsibility, and whoever leaves behind wealth, it will go to his heirs."
Hadith Referenceصحیح ابن حبان / كتاب الجنائز وما يتعلق بها مقدما أو مؤخرا / 3063
Hadith Gradingفضيلة الشيخ الإمام محمد ناصر الدين الألبانيصحيح - «صحيح أبي داود» (2619)، «أحكام الجنائز» (111/ 4) «أحاديث البيوع»: ق.فضيلة الشيخ العلّامة شُعيب الأرناؤوطإسناده صحيح على شرطهما