"A deceased man would be brought to the Messenger of Allah while a debt was due upon him. So he would say: 'Has he left anything to pay off his debt?' If he was told that he had left something to pay it then he would pray (the funeral prayer) for him. Otherwise he would tell the Muslims: 'Pray for your companion.' So when Allah granted him the victories, he stood and said: 'I am more worthy in the case of the believers than they themselves are. So whoever among the believers dies and leaves a debt behind, then it is up to me to fulfill it. And whoever leaves wealth behind, then it is for his heirs.'" (Using translation from Tirmidhī 1070)
أَنَّ رَسُولَ اللهِ ﷺ كَانَ يُؤْتَى بِالرَّجُلِ الْمُتَوَفَّى عَلَيْهِ الدَّيْنُ فَيَسْأَلُ هَلْ تَرَكَ لِدَيْنِهِ مِنْ قَضَاءٍ؟ فَإِنْ حُدِّثَ أَنَّهُ تَرَكَ وَفَاءً صَلَّى عَلَيْهِ وَإِلَّا قَالَ لِلْمُسْلِمِينَ صَلُّوا عَلَىصَاحِبِكُمْ فَلَمَّا فَتَحَ اللهُ عَلَيْهِ الْفُتُوحَ قَامَ فَقَالَ أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ فَمَنْ تُوُفِّيَ مِنَ الْمُؤْمِنِينَ فَتَرَكَ دَيْنًا فَعَلَيَّ قَضَاؤُهُ وَمَنْ تَرَكَ مَالًا فَهُوَ لِوَرَثَتِهِ