This excerpt is taken from the book of Sheikh al-Islam Imam Ibn Taymiyyah, may Allah have mercy on him, Al-Jawab al-Bahir fi Zuwar al-Maqabir, translated by Sheikh Ataullah Saqib.
Prohibited Acts on the Occasion of Visiting Graves
Therefore, visiting graves is prohibited when the prescribed acts are abandoned but forbidden acts are performed, such as wailing, inappropriate speech, and impatience, etc. Similarly, visiting graves is also prohibited if it involves shirk (associating partners with Allah), calling upon others besides Allah, and abandoning sincerity. Both types of visits are forbidden, but the latter is more severe in terms of sin. Hence, it is not permissible to pray facing the grave or near the grave. Because the Messenger of Allah, peace be upon him, said:
لا تصلوا إلى القبور ولا تجلسوا عليها
"Do not pray facing the graves, nor sit near them as if seeking nearness."
Reference: (Sahih Muslim, Book of Funerals: Chapter on the prohibition of sitting on graves and praying towards them, Hadith 972)
Thus, there are two types of visiting graves:
◈ The first is that which the Messenger of Allah, peace be upon him, forbade and upon which scholars agree that it is not legitimate. This is when graves are turned into places of worship, idol temples, or fairgrounds. Therefore, going there to perform obligatory or voluntary prayers is also wrong, and it is also wrong to worship the grave as one worships idols. Turning them into fairgrounds where people gather at a fixed time, like Muslims gather in Arafat and Mina, is also wrong.
◈ The second is the legitimate visit, which according to most scholars is recommended. Some scholars consider it permissible, and some say it is absolutely forbidden, the details of which have been discussed in previous pages. The legal evidence supporting it is that we should interpret the absolute texts in a restricted sense. In this case, there are three types of visits:
➊ Forbidden
➋ Permissible
➌ Recommended
According to Imam Malik, may Allah have mercy on him, the third type is correct, and he presents the same narrations and reports in its support, which mention visiting the Prophet’s Mosque, the Quba Mosque, Jannat al-Baqi, and the graves of the martyrs of Uhud.
The noble Messenger, peace be upon him, used to not go anywhere except these two mosques and two graveyards. He would perform the Friday prayer in his mosque and on Saturdays he would go to the Quba Mosque. As narrated in Sahihayn from Sayyiduna Abdullah bin Umar, may Allah be pleased with them both, who said:
إن النبى صلى الله عليه وسلم كان يأتى قباء كل سبت راكبا وماشيا فيصلي فيه ركعتين
"The Messenger of Allah, peace be upon him, used to go to the Quba Mosque every week on foot and sometimes riding, and perform two rak'ahs of prayer."
Reference: (Sahih Bukhari, Book of the Virtue of Prayer in Mecca and Medina: Chapter on going to the Quba Mosque walking or riding, Hadith 1193; Sahih Muslim, Book of Hajj: Chapter on the virtue of the Quba Mosque and praying therein, Hadith 1399)
There is an abundance of hadiths negating the turning of graves into places of worship, preserved in Sahihayn and other hadith books. A few of these hadiths are presented here for the esteemed readers.