Visiting the Graves of the Muslims and supplicating for the People in them is a Sunnah
Question :
I live in a neighborhood that has a graveyard and everyday I walk along a path that passes beside it. Actually, I walk along this path more than once everyday. What is obligatory upon me in this situation? Should I always give the greetings of peace to the deceased or what should I do? Please give me some direction, may Allâh bless you.
Answer :
Visiting the graves in the legislated manner is a Sunnah due to what it contains of reminding of the Hereafter and death, and what it contains of supplication for forgiveness, mercy and safety from the Fire for the deceased - if they were Muslims. This is due to the Prophet's statement:
"Visit the graves, for verily they remind you all of the Hereafter."
The Prophet used to teach his Companions to say when they visited the graves:
"Peace be upon you, O people of the abodes among the Muslims and the believers. If Allah wills, verily we will be joining you. We ask Allah for well-being for us and you."
The Hadiths concerning visiting the graves are numerous. It is legislated for you to give the greetings of peace every time you pass by the graves, to those who are in them and supplicate for forgiveness and well-being for them. Yet, this is not obligatory. Rather, it is recommended and it contains great reward. If you pass by the graves and you do not give the greetings of peace, there is no sin upon you. And success is from Allâh.
Source:
Ash-Shaykh Ibn Baz
Fatawa Islamiyah, Vol. 3 Pages