All three views are correct in their respective contexts. If a visit involves something forbidden—such as associating partners with Allah, lying, lamentation, wailing, or offensive speech—then it is forbidden by scholarly consensus. Such are the visits made by those who associate partners with Allah or resent His judgment; their visits are forbidden. For no religion is accepted except Islam, which means submission to His creative will and His commands. One submits to what He has ordained and decreed, and submits to what He commands and loves. We carry out His commands and call others to them; we accept His decree and rely upon Him concerning it. Thus, we are content with Allah as our Lord, Islam as our religion, and Muhammad as our Prophet.
In our prayers, we say:
“You alone we worship, and You alone we ask for help.”
This is like His saying, Most High:
“So worship Him and put your trust in Him.”
And His saying, Most High:
“Seek help through patience and prayer. Indeed, Allah is with the patient.”
And His saying, Most High:
“Establish prayer at the two ends of the day and in the early hours of the night. Indeed, good deeds do away with misdeeds. That is a reminder for those who remember.”
“And be patient, for Allah does not let the reward of those who do good go to waste.”
The second type is visiting graves simply out of grief for the deceased because of kinship or friendship. This is permissible, just as weeping over the deceased is permissible without lamentation or wailing. Thus:
“The Prophet, may Allah bless him and grant him peace, visited his mother’s grave and wept, causing those around him to weep. He said: ‘Visit graves, for they remind you of the Hereafter.’”
He had forbidden such visits because of the wrongful practices they used to engage in. Once they had come to understand Islam, he permitted them, because they serve a beneficial purpose: remembering death. Many people, when they see a relative who is