Sahih Muslim 1619 a
Abu Huraira (Allah be pleased with him) reported that when the body of a dead person having burden of debt upon him was brought to Allah's Messenger (ﷺ) he would ask whether he had left property enough to clear off his debt, and if the property left had been sufficient for that (purpose), he observed funeral prayer for him, otherwise he said (to his companions):
You observe prayer for your companion. But when Allah opened the gateways of victory for him, he said: I am nearer to the believers than themselves, so if anyone dies leaving a debt, its payment is my responsibility, and if anyone leaves a property, it goes to his heirs.
وَحَدَّثَنِي زُهَيْرُ بْنُ حَرْبٍ، حَدَّثَنَا أَبُو صَفْوَانَ الأُمَوِيُّ، عَنْ يُونُسَ الأَيْلِيِّ، ح وَحَدَّثَنِي حَرْمَلَةُ بْنُ يَحْيَى، - وَاللَّفْظُ لَهُ - قَالَ أَخْبَرَنَا عَبْدُ اللَّهِ بْنُ وَهْبٍ، أَخْبَرَنِي يُونُسُ، عَنِ ابْنِ، شِهَابٍ عَنْ أَبِي سَلَمَةَ بْنِ عَبْدِ الرَّحْمَنِ، عَنْ أَبِي هُرَيْرَةَ، أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم كَانَ يُؤْتَى بِالرَّجُلِ الْمَيِّتِ عَلَيْهِ الدَّيْنُ فَيَسْأَلُ ‏"‏ هَلْ تَرَكَ لِدَيْنِهِ مِنْ قَضَاءٍ ‏"‏ ‏.‏ فَإِنْ حُدِّثَ أَنَّهُ تَرَكَ وَفَاءً صَلَّى عَلَيْهِ وَإِلاَّ قَالَ ‏"‏ صَلُّوا عَلَى صَاحِبِكُمْ ‏"‏ ‏.‏ فَلَمَّا فَتَحَ اللَّهُ عَلَيْهِ الْفُتُوحَ قَالَ ‏"‏ أَنَا أَوْلَى بِالْمُؤْمِنِينَ مِنْ أَنْفُسِهِمْ فَمَنْ تُوُفِّيَ وَعَلَيْهِ دَيْنٌ فَعَلَىَّ قَضَاؤُهُ وَمَنْ تَرَكَ مَالاً فَهُوَ لِوَرَثَتِهِ ‏"‏ ‏.‏