Visiting graves is desirable for men. ‘Abdallah ibn Buraidah reported from his father that the Prophet, peace be upon him, said: “I had forbidden you to visit graves, but now you may visit them. It will remind you of the Hereafter.” (Muslim, Ahmad, and the Sunan works) They were prohibited from visiting the graves because of their proximity to the jahiliyyah (Days of Ignorance) when they used incorrect and obscene language. After they had fully entered the fold of Islam, became well pleased with it, and had fully accepted its laws, the Prophet, peace be upon him, permitted them to visit graves.
Abu Hurairah reported: “The Prophet, peace be upon him, visited his mother’ s grave and cried, and everyone there cried with him. Then the Prophet, peace be upon him, said: ‘I sought my Lord’s permission to seek forgiveness for her, but He did not permit me. I then sought permission to visit her grave and He permitted me to do this. You should visit graves, because they will remind you of the reality of death.” (Muslim, Ahmad, and the Sunan, except Tirmizhi)
Since the purpose of visiting graves is admonition and remembrance of death, it is permissible to visit the graves of disbelievers. Weeping when passing by the graves of the wrongdoers who were seized and punished by Allah for their evil deeds, and to express one’s humility and one’s need for forgiveness of Allah is desirable. This is obvious from a hadith, reported by Bukhari on the authority of Ibn ‘Umar, that the Prophet, peace be upon him, said to his Companions, when they passed through Al-Hijr, the dwellings of the people of Thamud, “Do not go without weeping to the places of burial of those who are undergoing torment. But if you cannot weep, then do not enter these places lest what befell them should befall you.”