The source and reasons behind visiting graves of Tzadikim, relatives and cemeteries:
The Biblical and Halachic source and custom for visiting graves:
It is a Jewish custom dating back to Biblical times, to visit the burial grounds of one’s relatives. We find that Kaleiv, in his touring trip of Eretz Yisrael, made a stop in Chevron, to pray by the Kever of our forefathers, the Avos. We likewise find, that Rachel was specifically buried on the road to Chevron so her descendants could visit her at a time of need and have her pray to Hashem on their behalf. This custom of visitations and prayer by the grave is not just limited to Kivrei Tzadikim, but was also practiced in regards to one’s relatives, even if they were not considered Tzadikim, as recorded in the Zohar and Poskim. Furthermore, the Talmud and Poskim direct that at certain times one is to visit a cemetery in order to arouse one to do Teshuvah, even if relatives or Tzadikim are not buried there. Furthermore, some Poskim rule that if the graves of Jews are unavailable, then one is to visit even the graves of gentiles, for this purpose of arousing one to do Teshuvah. Nonetheless, one is not to over increase on the visitation of graves and is not to go unnecessarily. See Halacha C for why visiting graves does not transgress the prohibition of Doreish El Hameisim.
B. The purpose and reason for visiting graves:
There are four reasons recorded behind the custom of visiting graves. As stated above, one is avoid visiting graves unnecessarily.
- Elevate the soul of the deceased: One of the purposes of visiting graves is to Daven on behalf of the deceased, in his merit, and help affect an elevation of his soul above in heaven.
- So the deceased intervenes on one’s behalf: Another reason for visiting graves is in order to inform the soul of any issues that one may be facing, and have them pray one one’s behalf. [The Zohar states as follows: When one visits a grave to beseech him about a certain problem, the Nefesh of the deceased goes and awakens the Ruach of the deceased, which then goes and awakens the Neshamah of the deceased, and effects that Hashem have mercy on the world.]
- Teshuvah: Another reason for visiting graves is in order to arouse oneself in Teshuvah, as while by the grave one remembers the day of death, and how his evil ways will lead to the same outcome as those buried there.
- Request forgiveness from the deceased: One who sinned against the deceased is to visit his grave request forgiveness from him, saying “I have sinned against the G-d of Israel, and this individual who I sinned against.” In such a case, the following order is practiced: If the grave is within a three Parsa distance, one is required to go barefoot to the grave together with ten other people and ask forgiveness from the deceased. If the grave of the person is further than a three Parsa distance, one may send a messenger together with another ten people, to the grave to ask forgiveness from the deceased.
 Sotah 34b
 Source for Kivrei Tzadikim: Sota 34b regarding Kalev; Michaber 344:20 based on Tur and Rav Haiy Gaon who mentions visitations of the grave of Chacham, Aluf, Vegaon at different periods within the first year; Rama 581:4 regarding visiting Kivrei Tzadikim on Erev Rosh Hashanah; M”A 581:16 “That one is to be Mishtateiach on Kivrei Tzaddikim”; Drashos Mahril; Elya Raba 581:39; Levush 579; Peri Megadim 581:16; Machatzis Hashekel 581:16; M”E 581:50; Kitzur SHU”A 128:13; M”B 581:27; Kaf Hachaim 581:95 and 98; Minchas Elazar 1:68 [brings many proofs from Midrashim; Talmud; Zohar]; Alef Hamagen 581:113; Minchas Yitzchak 8:53; Piskeiy Teshuvos 581:21; Maharam Shick 293 for a list of opinions on this matter;
 Zohar Teruma p. 141b; Achareiy Mos p. 70
 Shach Y.D. 179:15 in name of Y.D. Bach 217 “The Jewish people have already held on to this custom, and there is no prohibition”; Bach ibid states [after bringing the Maharam Ben Baruch who prohibits grave visiting] “The Jewish people have already held on to this custom, and there is no one who protests , and it has a source in the Zohar, to Daven by the grave of ones forefathers to be saved from punishment in their merit, and there is already a Seder Tefila printed for those who visit the graves of their forefathers, and no Rav should make people abstain and nullify this custom”; M”A 696:5 regarding Shiva that some are accustomed to do so for all deceased relatives at different periods of the year, such as the end of Shiva; Sefer Chassidim 450 “The deceased receive benefit when their loved ones visit their graves and request that their souls be given benefit, and indeed up on high they do give the soul benefit as a result.” Mavor Yabok Sifsei Rinanos 23; Gilyon Maharsha 179:15; See Maharil Hilchos Taanis; Poskim brought in Makor Chesed 3 on Sefer Chassidim 450; Peri Haretz 3:2; Mishmeres Shalom Hei 28; Toras Yekusiel Tinayna 92; See also Sefarim quoted in previous footnotes, Halacha B and in Halacha 3 regarding the Yartizte and other times of year that it is accustomed to visit the grave of the deceased.
Other opinions: Some Poskim prohibit, or discourage, the visiting of graves and praying there, due to it being similar to the prohibition of Doreish El Hameisim. [Teshuvas Maharahm Baruch [Rav Chaim Paltiel] 164, brought in Shach Y.D. 179:13 and Bach 217:51, that “Those who make a vow to visit the cemetery, it slightly seems like Doresh El Hameisim, as the allowance of Kaleiv was because it was a holy place of the Avos and he wanted his prayers to be heard. Likewise, we find a source for visiting a grave to ask for forgiveness. However, those who women and people who don’t know this. I do not know why they visit, and I am accustomed to refrain them from doing so”; See M”A 559:11 in name of Arizal that one should only go for the Levayah, especially if one is a Baal Keri, implying that one should avoid visiting graves; Directive of Gr”a to his family, brought in Mishemres Shalom Hei 31, that they should never visit cemeteries at all due to the abundance of Kelipos found there. This applies especially to women, and all the tragedies come due to this. Gesher Hachaim 29:8 that so is the custom of many not to visit graves; Custom of Brisk and Chazon Ish and Steipler; See Nitei Gavriel 82:7 footnote 15]
 Taanis 16a regarding fast for rain; Yuma 87a; Chagiga 16b; 22b; Makos 5b regarding asking forgiveness from deceased
 Michaber 579:3 regarding fast for rain; Admur 606:5 and Michaber 606:2 regarding asking forgiveness from deceased
 Rama 579:3 “According to this, if a Jewish cemetery is not available, then they are to visit the graves of gentiles.”; M”A 559:15; M”B 559:41; See Halacha D!
 M”A 559:11 in name of Arizal; See Nitei Gavriel 82:7
 Sefer Chassidim 450 “The deceased receive benefit when their loved ones visit their graves and request that their souls be given benefit, and indeed up on high they do give the soul benefit as a result.”
 Taanis 16a “In order so they pray on our behalf”; M”A 579:11; 559:15 in name of Shelah; Zohar Acharei Mos 71a and Teruma p. 141b [brought next]; Sefer Chassidim 450 “In addition, when asked, the souls in heaven pray on behalf of those alive.”; Bach Y.D. 217 “One may Daven by the grave of ones forefathers to be saved from punishment in their merit”; Drashos Mahril; Elya Raba 581:39; Levush 579; Peri Megadim 581:16; Machatzis Hashekel 581:16; M”E 581:50; Kitzur SHU”A 128:13; M”B 581:27; Kaf Hachaim 581:95 and 98; Minchas Elazar 1:68 [brings many proofs from Midrashim; Talmud; Zohar]; Alef Hamagen 581:113; Minchas Yitzchak 8:53; Piskeiy Teshuvos 581:21; Maharam Shick 293 for a list of opinions on this matter
 Zohar Acharei Mos 71a; Teruma p. 141b
 Michaber 579:1
 Admur 606:5; Michaber 606:2; Yuma 87a; Chagiga 16b; 22b; Makos 5b
 Approximately 5 hours of walking.
 Admur ibid; M”A 606:7; Rashal Yam Shel Shlomo 50