We learned in Shekalim (chapter two): The surplus of the deceased (plural) is for the deceased. The surplus of the deceased (singular) is for his heirs. How so? They collected donations for the deceased in general—this is the surplus of the deceased for the deceased. They collected for this specific deceased person—the surplus of the deceased is for his heirs (Sanhedrin 48a). The Ramban wrote that this is not because by law this deceased person acquired it, for preparation is not a significant act. Rather, it is because it would be a disgrace, as they collected in his name. Therefore, for his heirs he waives his disgrace, but not for others (Beit Yosef). And so it is explicitly stated in the Gemara ibid. And if the gabbai wishes to establish a monument for him from the surplus, or to place boards around his grave according to the custom, and the heirs protest against him—he should not obey them, and he should use the surplus for the needs of the deceased according to what is customary for all the deceased, and the remainder from this he shall give to the heirs. And a woman does not collect her ketubah from this surplus, nor does a creditor collect his debt, for the reason that has been explained, that only for his heirs does he waive his disgrace.
תנן בשקלים (פרק שני): מותר מתים – למתים. מותר המת – ליורשיו. כיצד? גבו נדבות למת סתם – זהו מותר מתים למתים. גבו למת זה – מותר המת ליורשיו (סנהדרין מח א). וכתב הרמב"ן דלאו מפני שמדינא זכה מת זה, שהרי הזמנה לאו מילתא היא. אלא משום דהוה ליה זילותא, שגבו על שמו. לפיכך ליורשיו מחל זילותיה, ולא לאחרים (בית יוסף). וכן מפורש בגמרא שם. ואם הגבאי רוצה להקים לו מצבה מהמותר, או להניח קרשים סביב קברו כפי הנהוג, והיורשים מוחים בידו – לא יציית להם, ויעשה בהמותר לצורך המת כפי מה שנהוג בכל המתים, והנותר מזה יתנן ליורשים. ואין אשה גובה כתובתה ממותר הזה, ולא בעל חוב את חובו, מטעם שנתבאר דרק ליורשיו מוחל זילותיה.