Sunan an-Nasa'i, Volume 3, Book 21, Hadith 1965 (DarusSalam)

It was narrated from Abu Hurairah that: if a believer died with debts outstanding, the Messenger of Allah would ask whether he had left behind anything to pay off his debts. If they said yes, he would pray for him, but if they said no, he would say: "Pray for your companion." Then, when Allah made His Messenger rich through conquest, he said: "I am closer to the believers than their own selves. Whoever dies and leaves behind a debt, I will pay it, and whoever leavers behind wealth, it is for his heirs."

أَخْبَرَنَا يُونُسُ بْنُ عَبْدِ الأَعْلَى، قَالَ أَنْبَأَنَا ابْنُ وَهْبٍ، قَالَ أَخْبَرَنِي يُونُسُ، وَابْنُ أَبِي ذِئْبٍ، عَنِ ابْنِ شِهَابٍ، عَنْ أَبِي سَلَمَةَ، عَنْ أَبِي هُرَيْرَةَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم كَانَ إِذَا تُوُفِّيَ الْمُؤْمِنُ وَعَلَيْهِ دَيْنٌ سَأَلَ ‏"‏ هَلْ تَرَكَ لِدَيْنِهِ مِنْ قَضَاءٍ ‏"‏ ‏.‏ فَإِنْ قَالُوا نَعَمْ صَلَّى عَلَيْهِ وَإِنْ قَالُوا لاَ قَالَ ‏"‏ صَلُّوا عَلَى صَاحِبِكُمْ ‏"‏ ‏.‏ فَلَمَّا فَتَحَ اللَّهُ عَزَّ وَجَلَّ عَلَى رَسُولِهِ صلى الله عليه وسلم قَالَ ‏"‏ أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ فَمَنْ تُوُفِّيَ وَعَلَيْهِ دَيْنٌ فَعَلَىَّ قَضَاؤُهُ وَمَنْ تَرَكَ مَالاً فَهُوَ لِوَرَثَتِهِ ‏"‏ ‏.‏

sunnah.com