Such condemnation applies only to idolatrous, innovative practices, not to the lawful form of visitation. Not a single sound ḥadīth from the Prophet ﷺ establishes the merit of visiting any specific grave, nor has anything of that sort been transmitted by the compilers of the Ṣaḥīḥ collections, the Sunan, or the authors of the Musnad works—Imām Aḥmad and others. Only those who collected fabricated reports have narrated such traditions. The most highly regarded narration they cite is that reported by al-Dāraqutnī, yet it is weak by unanimous agreement of the scholars. In fact, all the reports concerning a special virtue in visiting his grave—such as:
• “Whoever visits me and visits my father Abraham, the Close Friend, in the same year, I guarantee Paradise for him,”
• “Whoever visits me after my death, it is as though he visited me during my lifetime,”
• “Whoever performs ḥajj and does not visit me has shunned me,”
and the like—are fabricated and spurious.
The Prophet ﷺ, however, did grant general permission to visit graves after he had previously forbidden it. As is authentically reported, he said:
“I had forbidden you to visit graves; now go ahead and visit them.”
And in another sound narration he said:
“I asked my Lord’s permission to seek forgiveness for my mother, and He did not permit me; I then asked His permission to visit her grave, and He permitted me. So visit graves, for they remind you of the Hereafter.”
Thus, the purpose of this visit is to recall the Hereafter, and for that reason it is even permissible to visit the grave of a non-believer for the same reminder.