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."
أَنَّ رَسُولَ اللَّهِ ﷺ كَانَ إِذَا تُوُفِّيَ الْمُؤْمِنُ وَعَلَيْهِ دَيْنٌ سَأَلَ هَلْ تَرَكَ لِدَيْنِهِ مِنْ قَضَاءٍ فَإِنْ قَالُوا نَعَمْ صَلَّى عَلَيْهِ وَإِنْ قَالُوا لاَ قَالَ صَلُّوا عَلَى صَاحِبِكُمْ فَلَمَّا فَتَحَ اللَّهُ ﷻ عَلَى رَسُولِهِ ﷺ قَالَ أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ فَمَنْ تُوُفِّيَ وَعَلَيْهِ دَيْنٌ فَعَلَىَّ قَضَاؤُهُ وَمَنْ تَرَكَ مَالاً فَهُوَ لِوَرَثَتِهِ