This excerpt is taken from Sheikh al-Islam Imam Ibn Taymiyyah's book Al-Jawab al-Bahir fi Zuwar al-Maqabir, translated by Sheikh Ataullah Saqib.
Visiting the Graves of the Believers is Recommended
The majority of the Salaf of the Ummah hold the view that visiting the graves of the believers is recommended so that prayers may be made for them and salutations sent upon them. For example, it was the practice of the Messenger of Allah, peace be upon him, to go to Jannat al-Baqi and supplicate for them there. It is also established from the narrations in the two Sahihs that:
”إنه خرج إلى شهداء أحد فصلى عليهم صلاته على الموتى كالمودع للأحياء والأموات“
"He went to the graves of the martyrs of Uhud and supplicated for them as one would for a deceased person in a funeral prayer, as if he was bidding farewell to all the living and the dead."
Reference: (Sahih al-Bukhari, Book of Funerals: Chapter on Prayer for the Martyr, Hadith 1344; Book of Military Expeditions: Chapter on the Battle of Uhud, Hadith 4042; Sahih Muslim, Book of Virtues, Hadith 2296)
The Sunnah Supplication for Visiting Graves
It is in Sahih Muslim that the Messenger of Allah, peace be upon him, used to teach the companions, may Allah be pleased with them, this supplication for visiting graves:
السَّلَامُ عَلَيْكُمْ أَهْلَ الدِّيَارِ مِنَ الْمُؤْمِنِينَ وَالْمُسْلِمِينَ وَإِنَّا إِنْ شَاءَ اللَّهُ بِكُمْ لَاحِقُونَ يَرْحَمُ اللَّهُ الْمُسْتَقْدِمِينَ مِنَّا وَمِنْكُمْ وَالْمُسْتَأْخِرِينَ نَسْأَلُ اللَّهَ لَنَا وَلَكُمُ الْعَافِيَةَ اللَّهُمَّ لَا تَحْرِمْنَا أَجْرَهُمْ وَلَا تَفْتِنَّا بَعْدَهُمْ وَاغْفِرْ لَنَا وَلَهُمْ
"O believers! Peace be upon you. We, God willing, are also going to meet you. May Allah have mercy on you and on us all. We ask Allah for well-being for ourselves and for you. O Allah! Do not deprive us of their reward. And do not subject us to any trial after them. O Allah! Forgive them and all of us."
Reference: (Sahih Muslim, Book of Funerals: Chapter on what is said when entering graves, Hadith 975, 974)
This was the Sunnah way of visiting the graves of the believers. As for the disbelievers, it is also permissible to visit their graves so that the remembrance of the Hereafter is renewed. However, seeking forgiveness for them is not permissible. In Sahih Muslim, there is a narration from the Messenger of Allah, peace be upon him, himself:
أَنَّهُ زَارَ قَبْرَ أُمِّهِ فَبَكَى وَأَبْكَى مَنْ حَوْلَهُ وَقَالَ اسْتَأْذَنْتُ رَبِّي فِي أَنْ أَزُورَ قَبْرَهَا فَأَذِنَ لِي وَاسْتَأْذَنْتُهُ فِي أَنْ أَسْتَغْفِرَ لَهَا فَلَمْ يَأْذَنْ لِي فَزُورُوا الْقُبُورَ فَإِنَّهَا تُذَكِّرُكُمُ الْآخِرَةَ
"He, peace be upon him, went to the grave of his mother and wept there and made his companions weep as well. Then the Prophet said: I asked Allah for permission to visit her grave and it was granted. I asked for permission to seek forgiveness for her but it was not granted. So visit the graves, for they remind you of the Hereafter."
Reference: (Sahih Muslim, Book of Funerals: Chapter on the Prophet's permission from his Lord to visit his mother's grave, Hadith 976)
Whose Opinion to Follow in Case of Disagreement Among Scholars?
In matters where scholars disagree, the opinion of the one who has a Shariah-based proof should be accepted. It may be that one does not have a Shariah evidence. The reality is that scholars are the true inheritors of the Prophets. Allah Almighty says:
Reference: And [mention] David and Solomon, when they judged concerning the field - when the sheep of the people had grazed therein by night, and We were witnesses to their judgment. So We gave understanding of the case to Solomon, and to each [of them] We gave judgment and knowledge. And We subjected the mountains to [praise] with David, and the birds [as well]. And We were doers. (78-79)
"Remember the event when David and Solomon were judging a case concerning a field in which the people's sheep had spread at night, and We were witnesses to their judgment. At that time, We made Solomon understand the correct judgment, although We had given both of them judgment and knowledge."
Reference: (21-Al-Anbiya:78-79)
Three Types of Visiting Graves Based on Intention and Action
The above three statements are different in various respects.
◈ If the visitation of graves is associated with polytheism, falsehood, wailing, lamentation, etc., then such visitation is unanimously forbidden. Like the actions of the polytheists and the disobedient servants of Allah. Because the religion beloved to Allah is Islam, and it requires that one submit humbly to the commands of Allah. His decisions must be accepted wholeheartedly. Whatever He commands must be obeyed, and whatever He loves must be loved. We act upon this and invite people towards it, and our trust is in this One and Only Being. We are satisfied with Allah being our Lord, Islam being the religion, and Muhammad (peace be upon him) being the Prophet, and in our prayers, we acknowledge that:
إِيَّاكَ نَعْبُدُ وَإِيَّاكَ نَسْتَعِينُ
"We worship You alone and seek help from You alone."
Reference: (1-Al-Fatiha:5)
We also make this acknowledgment because Allah Almighty has said:
فَاعْبُدْهُ وَتَوَكَّلْ عَلَيْهِ
"So, O Prophet! Worship Him and rely upon Him."
Reference: (11-Hud:123)
يَا أَيُّهَا الَّذِينَ آمَنُوا اسْتَعِينُوا بِالصَّبْرِ وَالصَّلَاةِ ۚ إِنَّ اللَّهَ مَعَ الصَّابِرِينَ
"O you who have believed! Seek help through patience and prayer. Indeed, Allah is with the patient."
Reference: (2-Al-Baqarah:153)
وَأَقِمِ الصَّلَاةَ طَرَفَيِ النَّهَارِ وَزُلَفًا مِّنَ اللَّيْلِ ۚ إِنَّ الْحَسَنَاتِ يُذْهِبْنَ السَّيِّئَاتِ ۚ ذَٰلِكَ ذِكْرَىٰ لِلذَّاكِرِينَ ﴿١١٤﴾ وَاصْبِرْ فَإِنَّ اللَّهَ لَا يُضِيعُ أَجْرَ الْمُحْسِنِينَ ﴿١١٥﴾
"And establish prayer at the two ends of the day and at the approach of the night. Indeed, good deeds remove bad deeds. That is a reminder for those who remember Allah. And be patient. Indeed, Allah does not allow to be lost the reward of the doers of good."
Reference: (11-Hud:113)
◈ The second type of grave visitation is that it is done only out of grief for the deceased, due to kinship and friendship. This visitation is permissible, like crying without wailing and lamentation is permissible.
For example, the Messenger of Allah (peace be upon him) visited the grave of his mother, there he himself wept and his companions also wept. Then he said:
زوروا القبور فإنها تذكركم الآخرة
"Visit the graves, for they remind you of the Hereafter."
Reference: (Sahih Muslim, Book of Funerals: Chapter on the Prophet's permission to visit his mother's grave, Hadith: 976)
Before this, he (peace be upon him) had prohibited such visitation because people used to commit un-Islamic acts at the graves of their relatives. After some time, when the knowledge of Islamic rulings became firmly established in the hearts of Muslims, then its permission was granted because the visitation of graves contains the reminder of death. The condition of most people is that when they see the grave of a relative, the spirit of preparing for the Hereafter arises in their hearts, and sometimes at that moment, distress and panic also occur, which creates two conflicting matters. That is, in itself, visiting graves is permissible. But if the purpose is purely obedience, then this visitation will be commendable, and if any un-Islamic act is involved, then it falls within the scope of sin.
◈ The third type is that the intention is to supplicate and seek forgiveness for the deceased. Such visitation is considered recommended. The Sunnah of the Prophet (peace be upon him) indicates its recommendation because he himself visited in this manner and specifically instructed the noble companions (may Allah be pleased with them) to do so.
As for the visitation of the Quba Mosque! Whoever goes to Madinah Munawwarah, it is recommended for him to go to the Quba Mosque and offer two units of prayer, and also to visit the graves of Jannat al-Baqi and the martyrs of Uhud, as was the practice of the Messenger of Allah (peace be upon him).
Prayers Should Be Made for the People of the Graves
The purpose of visiting graves is to make prayers for the owner of the grave. However, it is not permissible to turn the grave into a place of worship. It is also forbidden to believe that prayers made at the grave are accepted more quickly or that praying at the grave is superior to praying at home or in a mosque. Yes! The Imams of Islam agree that going to the cemetery and making prayers for the people of the graves is better than participating in the funeral prayer. This is both permissible and a communal obligation (Fard Kifayah).