It was narrated from Abu Hurairah that:
if a believer died at the time of the Messenger of Allah (ﷺ) and he had debts, the Messenger of Allah (ﷺ) would ask: "Did he leave anything with which to off his debt?" If they said yes, then he would offer the funeral prayer for him, but if they said no, then he would say: "Pray for your companion." When Allah granted his Prophet (ﷺ) the conquests, he said: "I am nearer to the believers than their own selves. Whoever dies owing a debt, I will pay it off for him, and whoever leaves behind wealth, it will be for his heirs."
English reference: Vol. 3, Book 15, Hadith 2415
Arabic reference: Book 15, Hadith 2508