Praise be to Allah, Lord of the Worlds, and may peace and blessings be upon our Prophet Muhammad, his family, and Companions.
I was asked about the ruling on Tawassul (supplicating to Allah) in the name of the dead and visiting graves and I gave the following answer:
If by visiting graves one intends to supplicate to the dead, try to get closer to them through offering them slaughtered animals and vows, seek their help, and supplicate to them instead of Allah, these will be acts of major Shirk (associating others with Allah in His Divinity or worship). The same ruling applies to some practices done by some people toward the socalled Awliya' (pious people), whether they are alive or dead. Such people believe that the Awliya' can benefit or harm them, answer their supplications, or cure their illnesses. Actually, all such practices pertain to major Shirk (we seek Allah's refuge).
Moreover, such practices resemble those done by Mushriks (those who associate others with Allah in His Divinity or worship) toward AlLat, Al`Uzza, Manat, and other idols of theirs.
It is obligatory for those in authority and scholars in Muslim countries to deny such practices and to teach people such parts of Shari`ah (Islamic law) as deemed indispensable. They also have to eliminate such acts of Shirk and prohibit laypeople from committing them. Moreover, they should pull down domes built over graves as they are Fitnah (trial) and lead to Shirk. The Messenger (peace be upon him) prohibited building on graves, plastering them, sitting over them, or offering Salah (Prayer) while facing them. Furthermore, He (peace be upon him) cursed those who take graves as places of worship. Therefore, no Masjids (mosques) or any other buildings are to be built thereupon. Rather, they should be protruding whereupon there is no building as were the graves of early Muslims in Madinah and as the case in many Muslim countries that have not been affected by Bid`ahs (rejected innovations in religion) and personal desires.
As for visiting graves to remember Allah and death, supplicate to Allah and ask His Mercy for the dead, it is a Sunnah (a commendable act) as far as men are concerned so long as no journeys are undertaken for that purpose. This is based on the Hadith of the Prophet (peace be upon him) that reads: Visit the graves for they remind you of the Hereafter. (Related by Muslim in his Sahih (authentic) Book of Hadith)
Moreover, the Prophet (peace be upon him) taught his Sahabah (Companions) to say on visiting graves: Peace be upon people of the households (graveyard) from among the believers and we shall, In Sha'aAllah (if Allah wills), join you. We ask Allah for wellbeing for you and us. May Allah have mercy on those who have gone ahead of us and those who come later on.
Furthermore, AlTirmidhy (may Allah be merciful with him) reported Ibn `Abbas (may Allah be pleased with both of them) as saying: Once the Prophet (peace be upon him) passed by graves in Madinah. He turned his face toward them saying: 'Peace be upon you, O dwellers of these graves. May Allah forgive you and us. You have preceded us, and we are following your trail.'
Actually, there are many Hadith to the same effect.It is recorded in the Two Sahih Books of Hadith (i.e. Al Bukhari and Muslim)on the authority of Abu Sa`id AlKhudry (may Allah be pleased with him) that the Prophet (peace be upon him) said: Do not undertake journeys but to three Masjids: AlMasjid AlHaram (the Sacred Mosque in Makkah), this Masjid of mine, and AlMasjid AlAqsa (the Aqsa Mosque in Jerusalem).
May Allah grant us success! May peace and blessings be upon our Prophet Muhammad, his family, and Companions!