One of the forms of magic and sorcery which the Torah forbids in Parashat Shoftim is “Doresh El Ha’metim” (Debarim 18:11) – consulting with the dead. The Sefer Ha’hinuch explains that sorcerers would starve themselves and go to the cemetery to sleep, and during the night, the spirits of the deceased would allegedly appear to them in a dream and reveal information about the future. Some who practiced this form of witchcraft would offer incense, and some would wear special types of clothing, in order to receive communication from the dead.
The prohibition against performing such practices applies in all times and places, and is binding upon both men and women. The Sefer Ha’hinuch writes that one who violates this command is liable to Malkut, as this violation is committed by performing certain actions.
In light of this prohibition, the Poskim address the question as to the validity of the practice of praying at the graves of Sadikim. One of the Rishonim – Rav Haim Paltiel (France, 13th century) – maintained that this practice falls under the category of “Doresh El Ha’metim,” and is thus forbidden. Others, however, disagree, noting the Gemara’s famous account in Masechet Sota (34) of Kaleb’s visit to the gravesite of the patriarchs in Hebron to pray for assistance. Some refuted this proof, contending that Kaleb, an outstanding Sadik, knew the right way to pray at a gravesite, but this example should not be followed by the masses. By contrast, some Poskim argued that this account indeed sets a precedent from which we can and should learn.
We find three different explanations as to why praying at a gravesite does not constitute a violation of “Doresh El Ha’metim.” One approach is that the gravesite of a Sadik has sanctity, and this is why it became customary to pray at such sites. There is no communication whatsoever between the one who prays and the deceased; one simply prays to Hashem at the site because of its special sanctity, which increases the chances of the prayer’s acceptance. Others explain that it is acceptable to ask the spirit of the deceased to serve as a Melitz Yosher (advocate) and pray to Hashem on his behalf. Such a request is not considered “Doresh El Ha’metim” because one is not consulting with the dead, or asking for their direct assistance, but rather requesting that they pray to Hashem on his behalf. Others claim that when praying at a gravesite one asks that Hashem should accept his pleas and grant him the assistance he needs in the merit of the deceased.
Accordingly, the Bah (“Bayit Hadash” by Rav Yoel Sirkis, Poland, 1561-1640) writes that the practice of praying at gravesites should not be discontinued, though he advises instructing the masses not to pray directly to the deceased. This ruling is brought by the Mishna Berura (581:27), and this is, of course, the widespread custom.
In conclusion, then, it is certainly a worthwhile practice to pray at the graves of Sadikim, though one must ensure to speak only to G-d, and not to the deceased, or, at most, turn to the deceased and ask that he intercede on his behalf, without praying to him directly, which could transgress a Biblical command.

