The practice of marking graves with stones has deep roots: Yaakov set up a matzevah over Rachel's grave (the Sforno (Bereishit 35:20), who explains this was done because the grave lay by the roadside and there was concern that the site would otherwise be lost to future desecration), and the piling of stones over Avshalom's burial pit is recorded as the biblical practice for marking a grave-site (Shmuel II 18:17-18).
The Rambam rules that earth and stones are restored over the grave and that cemeteries are marked out, with a structure (a 'nefesh') built over the grave — except for the truly righteous, whose grave need not be built up since their words are their memorial (Mishneh Torah, Mourning 4:4).
The Shulchan Arukh addresses the halachic status of the grave-marker itself: a built grave is forbidden for benefit, though the bare earth of a grave is not; some hold that earth which was removed and replaced is also forbidden, and there is a dispute about whether one may sit upon the stone placed on a grave as a monument, with some prohibiting and others permitting (Shulchan Arukh, Yoreh De'ah 364:1).
The Gemara in Sanhedrin discusses leftover funds collected for a burial, recording the view of Rabbi Natan that such funds may be used to add another row of stones over the grave of the deceased, showing that enhancing the grave-marker was an accepted use of funds designated for the deceased's honor (Sanhedrin 48a:17).
Later poskim describe the actual custom of placing a stone at the grave: Rav Eliezer Melamed records that many visitors place a small stone on the matzevah as a sign that they were there, alongside the practice of erecting a matzevah by the thirtieth day inscribed with the deceased's name and dates (Peninei Halakhah, Family 10:13); Rav Gavriel Zinner likewise records that there is significance to placing a stone on a grave, more than, say, inserting a leaf, and notes a Jerusalem custom of setting a smooth stone immediately after burial along with practices of several chevrot kadisha (Nitei Gavriel, Aveilus vol 1, perek 77), and in a related passage records a custom for members of the burial society to place a small stone on each grave when leaving (Nitei Gavriel, Aveilus vol 1, perek 76).
Rav Tucazinsky describes the physical form of the grave itself — earth and small stones around it, with a smooth stone placed temporarily on the grave bearing the deceased's name until the permanent matzevah is built — reflecting the practical reality that a stone marker, temporary or permanent, is part of how a grave is treated after burial (Gesher HaChaim 16).
The Radbaz discusses a related practice in Egypt of placing large stone matzevot inscribed with the deceased's name, addressing whether reusing such a stone for another deceased person, after its inscription is erased, carries any prohibition, and concludes that even though there is a dispute whether the matzevah falls under the prohibition on benefiting from grave appurtenances, we are stringent about it out of concern that it may be considered a golel, though in the case described he rules leniently that the stone may be given to mark another grave, since it is not comparable to a grave dug for one's father which may not then be reused (Teshuvot HaRadbaz Volume 2 741:1-2).
The Chatam Sofer takes up a dispute about a matzevah inscribed with a holy name (shem kodesh), where a rav had ruled that such a stone should not be erected over the grave, citing a concern drawn from Masechet Soferim that such an inscription should be buried away rather than left exposed, and the Chatam Sofer engages with this ruling, invoking the precedent of a similarly inscribed matzevah for the Rif (Responsa Chatam Sofer, Collected Responsa 5:2-3).
Rav Moshe Feinstein, addressing the practical question of marking graves, holds that burial customarily requires the grave to be visibly raised above the surrounding ground and that a matzevah is required for the deceased, while the question of imposing such expenses on relatives depends on prior obligations and communal regulations (Igros Moshe YD 3:154).
Other sources on the sheet touch related but distinct themes: Sotah 14a teaches that God Himself buried the dead, as the pasuk states that He buried Moshe in the valley, and that one should therefore emulate this by burying the dead (Sotah 14a:4); Vayikra Rabbah speaks of the merit of having a marker — even a nail or stake — fixed in a cemetery plot (Vayikra Rabbah 5:5); the Kitzur Shulchan Arukh records the practice of placing one's left hand on the grave while reciting a formula of blessing at a cemetery visit (Kitzur Shulchan Arukh 128:13); the Mishnah Berurah discusses placing an item in a clean, respectful place (Mishnah Berurah 171:23-24); the Shulchan Arukh Orach Chayim addresses burial activities permitted on the second day of Yom Tov (Shulchan Arukh, Orach Chayim 526:4); the Rambam limits where the Shema may be recited near a grave or corpse (Mishneh Torah, Reading the Shema 3:2); and Rav Mordechai Eliyahu discusses the custom of placing a small stone under one's head in memory of Yaakov's stone at the site of the future Beit HaMikdash (Maamar Mordechai Hilchot Taaniyot U'Vein HaMetzarim 27:22).