Placing a stone over a grave is an ancient Jewish custom. Referring to Rachel’s burial, Genesis (35:20) states, “Over her grave Jacob set up a pillar (matzeivah).” While the Sforno (Italy, 16th century.) says that Jacob just wanted to make sure the grave would be secure on the side of the road, Rabbi Moshe Feinstein says that setting a stone to mark Rachel’s grave was a divine command.
The Mishnah gives two reasons for a matzeivah: to honour the deceased and to warn people (in particular, priests) that the area bears halachic impurity). Malbim, the 19th century halachist and biblical commentator, saw the purpose of the tombstone as a reminder to future generations of the deeds of the deceased.
The rituals around the stone-setting, such as reciting Psalms, evolved in the 20th century when having a special ceremony (or unveiling, as it’s called in America) became a significant part of marking someone’s passing.