All perfect praise be to Allaah, The Lord of the Worlds. I testify that there is none worthy of worship except Allaah, and that Muhammad, sallallaahu ‘alayhi wa sallam, is His slave and Messenger.
Visiting graves is legislated in order to get admonition and remember death, and in order to supplicate Allaah to forgive and have mercy on the dead people who are in the graveyard.
As regards what the Sufis do, like visiting some graves while believing that the person in the grave can benefit them or harm them, or for seeking blessings from its soil, or celebrating an anniversary at the grave, then all these acts are innovations. Had this been legislated, our pious predecessors among the companions and the generation which followed them and those who followed them in righteousness would have preceded us in doing so. The worst of all this is that they call upon the people of the grave and seek their help instead of seeking the help of Allaah; this is indeed a major Shirk and Allaah does not forgive the one who dies upon it. How could it be possible to ask the people of the grave for help while we ask Allaah to forgive and have mercy upon such dead helpless people?
As regards the visit of the Prophet to the graveyard of the companions like the martyrs of Uhud and others, it was for those legislated objectives and not for celebrating a birthday and the like. Had the companions understood other than the above legislated objectives, they would have followed the Prophet in it. Therefore, such inference is not correct and it is even a far reaching inference to provide the verse about Yahya (John) as evidence because there is absolutely no relation between Allaah informing us that he is safe in this life, in the Barzakh and in the Hereafter –among which is when he died –and celebrating his death anniversary.
For more benefit, please refer to Fataawa 84957, 88285 and 88265.
Allaah Knows best.