The Messenger of Allah ﷺ said, "I am closer to every believer than his own self. Whoever leaves behind wealth, it goes to his family, and whoever leaves behind a debt or dependents in need, then their care falls to me and is my responsibility."
قال رسول الله ﷺ: أنا أولى بكل مؤمن من نفسه، من ترك مالا فلأهله، ومن ترك دينا أو ضياعا فإلي وعلي.
Muslim narrated it in the Book of Jumuah (43/867), from Muhammad bin Muthanna, who said, Abdul-Wahhab bin Abdul-Majid narrated to us, from Jafar bin Muhammad, from his father, from Jabir bin Abdullah, who mentioned it at the end of a long hadith.The meaning of Allah's statement, "The Prophet is closer to the believers than their own selves", is that Allah Most High informs us in this noble verse that the Prophet ﷺ is closer to the believers than they are to themselves, because he ﷺ gave them such sincere counsel and care as would benefit them in this world and the next. So it is upon them to deal with him according to his rank, giving his love precedence over their love for all other created beings, even over their own parent and child, and if what he wanted differed from what others wanted, they should give precedence to what he wanted.It was part of his ﷺ excellent character that he would take upon himself the debts of believers who died, even though this was not obligatory upon him, while whatever the deceased left behind belonged to his heirs.A benefit drawn from this is that it is permissible for a ruler after the Prophet ﷺ to take upon himself the private debts of debtors and pay them off from the state treasury if he sees benefit in doing so, just as he may also forgive claims belonging to the public treasury of the state. All of this is permissible for a ruler.This also contains encouragement for wealthy people to pay off the debts of the poor, so that they are not punished for them in the hereafter.