Praise be to Allaah.
Visiting graves is a Sunnah which provides a lesson and a reminder. If the graves are those of Muslims, one should make du’aa’ for them… The Prophet (peace and blessings of Allaah be upon him) used to visit graves and make du’aa’ for the deceased, as did his companions, may Allaah be pleased with them. The Messenger (peace and blessings of Allaah be upon him) said: “Visit the graves, for they remind you of the Hereafter.” He used to teach his companions, when they visited graves, to say, “Al-salaamu ‘alayum ahl al-diyaar min al-mu’mineen wa’l-muslimeen, wa innaa in sha Allaah bikum laahiqoon. Nas’al Allaaha lana wa lakum al-‘aafiyah (Peace be upon you O inhabitants of the dwellings, believers and Muslims. If Allaah wills, we shall join you soon. We ask Allaah to keep us and you safe and sound.).”
According to the hadeeth of ‘Aa’ishah: “Yarham Allaah al-mustaqdimeena minna wa’l-musta’khireen (may Allaah have mercy on those of us who went first and those who will join them afterward).” According to the hadeeth of Ibn ‘Abbaas “yaghfir Allaah lana wa lakum, antum salafuna wa nahnu fi’l-athr (May Allaah forgive us and you. You are our predecessors and we are following in your footsteps).” Making du’aa’ for them in these or similar words is all good. Visiting them brings a reminder and a lesson to the believer to prepare for what has befallen them, i.e., death, for what happened to them will happen to him too. So let him make preparations and strive to obey Allaah and His Messenger (peace and blessings of Allaah be upon him), and keep away from that which Allaah and His Messenger have forbidden. Let him repent from his previous shortcomings. This is how the believer is to benefit from visiting graves.
With regard to what is mentioned (in the question) about visiting the graves of ‘Ali (may Allaah be pleased with him), al-Hasan, al-Husayn and others being equivalent to seventy Hajj – this is a lie and is falsely attributed to the Messenger (peace and blessings of Allaah be upon him), and it has no basis. Visiting the grave of the Prophet (peace and blessings of Allaah be upon him), who is the best of all, is not equivalent to one Hajj; this visit has its status and virtues, but it is not equivalent to Hajj, so how about visits to anyone else’s grave? This is a lie, as is the phrase “Whoever visits the members of my household (ahl bayti) after I die will have seventy Hajj recorded for him.” All of this has no basis at all and all of it is false. All of it is lies made up by the liars. The believer has to beware of these fabricated things that have been falsely attributed to the Messenger (peace and blessings of Allaah be upon him). It is Sunnah to visit the graves whether they are graves of the members of his household (Ahl al-Bayt) or other Muslims; (it is Sunnah) to visit them, make du’aa’ for them, pray for mercy for them and then leave.
If they are the graves of kaafirs, they may be visited for the purpose of learning a lesson and being reminded, without making du’aa’ for them. The Prophet (peace and blessings of Allaah be upon him) visited his mother’s grave, but his Lord forbade him to pray for forgiveness for her. He visited her grave for the purpose of the lesson and reminder, but he did not pray for forgiveness for her. This applies to all other graves – graves of kaafirs – if a believer visits them for the purpose of the lesson and reminder, there is nothing wrong with that, but he should not greet them with salaams or pray for forgiveness for them, because they do not deserve that.