Sayyiduna Abdullah bin Amr (may Allah be pleased with him) narrates that the Prophet (peace and blessings be upon him) said: "There are three situations in which, if a person takes a loan and dies without repaying it, Allah Almighty will have it paid on his behalf: a man who is in the path of Allah (in jihad) and his clothing wears out, and he fears that his private parts will now become exposed" (or some other word similar to this) "and then he dies without having repaid the loan; a man in whose presence a Muslim dies, and he finds nothing with which to shroud him or to cover his body (so he takes a loan to arrange the shrouding and burial), and then he himself dies before repaying the loan; and a man who fears falling into sin and wishes to preserve his chastity by marrying a woman (so he takes a loan and marries), and then dies before repaying the loan. On the Day of Resurrection, Allah Almighty will have the loan paid on that person's behalf."
Imam al-Bazzar recorded it; its chain contains a narrator, Abd al-Rahman bin Ziyad bin An'um, who is da'if (weak), although he has also been declared trustworthy.
It is also found with Imam Ibn Majah, with a difference in part of it.
Hadith Referenceمجمع الزوائد ومنبع الفوائد / كتاب البيوع / 6663