Halachah · Shulchan Aruch

Shulchan Arukh, Yoreh De'ah 356/שולחן ערוך·יורה דעה שנ״ו

א
גבו לצורך המת והותירו. ובו סעיף אחד:
מת שלא היה לו צרכי קבורה וגבו לו והותירו אם כשגבו יחדו לצרכי זה המת ינתנו ליורשיו ואם לאו יעשו מהם צרכי מתים אחרים:
1
A dead person who did not have [sufficient funds] for the burial needs and they raised [money] for his sake and there was a surplus; if at the time they collected the [money it was done specifically] for the needs of this particular dead person, [the surplus] should be given to his heirs; but if not [collected specifically for this particular person, the surplus] should be used for the needs of other dead.1