Abu Hurairah reported,

Whenever a deceased man with outstanding debt was brought to the Messenger of Allah ﷺ, he would ask whether the man had left behind enough to cover his debt. If he was told that the man had left sufficient means, he would perform the funeral prayer over him. Otherwise, he would say to the Muslims, "Pray over your companion."When Allah granted him the conquests, he said, "I am closer to the believers than they are to themselves. Whoever among the believers dies leaving a debt, its payment is upon me, and whoever leaves wealth, it belongs to his heirs."

Bukhari 5371

Sahih

حدثنا يحيى بن بكير حدثنا الليث عن عقيل عن ابن شهاب عن أبي سلمة

عن أبي هريرة رضي الله عنه

أن رسول الله ﷺ كان يؤتى بالرجل المتوفى عليه الدين فيسأل هل ترك لدينه فضلا فإن حدث أنه ترك وفاء صلى وإلا قال للمسلمين صلوا على صاحبكم فلما فتح الله عليه الفتوح قال أنا أولى بالمؤمنين من أنفسهم فمن توفي من المؤمنين فترك دينا فعلي قضاؤه ومن ترك مالا فلورثته

البخاري 5371صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Expenditures
Chapter
Saying of the Prophet ﷺ, "Whoever leaves behind dependents or debt, it is to me"
Numbering
Darussalam 5371
Bukhari 5371