There is a custom that many people observe to visit the cemetery on Ereb Rosh Hashanah and recite special prayers. The basis for this custom is the Gemara’s comment in Masechet Ta’anit (16) that when fast days were declared in response to drought, the people would go to the cemetery. The Gemara explains that they went there for two reasons: to express the notion that they felt lowly like the dead, and so that the souls of the deceased would intercede on their behalf during their time of need. Tosefot (Medieval commentaries by French and German scholars) note that this forms the basis of the custom to visit cemeteries on Tisha B’Ab and other public fasts.
Another Talmudic basis for this custom is the Gemara’s comment in Masechet Sota (14) that G-d concealed the whereabouts of Moshe Rabbenu’s grave so that the Jews would not pray by the site. G-d knew that the Jews would sin and have to be driven into exile, and if they would have been able to pray at Moshe’s grave and ask him to intercede on their behalf, the decree would have had to be rescinded. The reason, the Gemara adds, is because "the righteous are more precious after their death than during their lifetime." This demonstrates the value of praying by the graves of the righteous, and thus the Rama (Rav Moshe Isserles of Cracow, Poland, 1525-1572) writes (in Siman 559) that it is customary to pray in the cemetery on Ereb Rosh Hashanah that the souls of the righteous should intercede on our behalf as we stand judgment.
Interestingly, the Kaf Ha’haim (Rav Yaakob Haim Sofer, 1870-1939) cites the Regel Yeshara who questions this practice, noting that this would seem to constitute "Lo’eg La’rash" – "taunting" the deceased by praying in their presence, performing a Misva which they are no longer capable of performing. At first glance, performing Misvot in the presence of the deceased would have the opposite effect than that which we desire, as they will be resentful of this public display of Misvot. In truth, however, as Hacham Ovadia Yosef discusses in Hazon Ovadia – Yamim Noraim (p. 52), this is no question at all. The prohibition of "Lo’eg La’rash" would be violated if one recites a mandatory prayer in a graveyard. Here, we are talking of voluntary supplications that a person recites specifically asking the souls of the righteous to intercede on our behalf. This is not "taunting" them at all. The clear proof to the validity of this practice is the story of Kaleb, one of the twelve scouts who, during the scouts’ excursion through Eretz Yisrael, went to Hebron to pray by the gravesites of the patriarchs. This certainly indicates that praying by the graves of the righteous is perfectly acceptable.
However, when praying at a gravesite, one must remember that he is there not to pray to the righteous people buried there, but rather to invoke their merit and to ask them to intercede on our behalf.
The Sefer Hasidim (Rav Yehuda Ha’hasid, Germany, late 12th-early 13th century), in Siman 450, tells that Barzilai Ha’Gil’adi (a person mentioned in the Tanach) expressed his interest in being buried in the city of his residence, because the deceased derive benefit when their family members visit their graves and pray for the souls. These visits, the Sefer Hasidim writes, also bring merit to the visitors. Likewise, the Zohar tells that somebody once asked a spirit in the graveyard whether the souls of the deceased pray for the living, and the spirit said, "If not for our prayers, the living would be unable to continue existing for even half a day." These sources clearly demonstrate the value and importance of praying by the gravesites of the righteous, whose souls will then pray on our behalf.
This custom of visiting the gravesites of the righteous on Ereb Rosh Hashanah is codified in the Yalkut Yosef (English edition, p. 98).
Summary: There is a custom to visit the graves of Sadikim on Ereb Rosh Hashanah to ask the souls to pray on our behalf and to invoke their merit as we stand judgment.