The command of visiting graves included both men and women without any limitation of time period, place, etc. The word "Visit them" abrogates the earlier command of it being forbidden. As related by Hadhrat Shaykh Abdul Haq Muhaddith Dehlwi (May Allah Ta'ala shower His mercy on him) in Ash'atul Lam'iaat, Vol. 1, Pg. No. 764.
There is a Hadith:
It has been narrated on the authority of Hadhrat Abdullah Ibn Mas‘ud (May Allah Ta'ala be well pleased with him) that the Holy Prophet (Sallallahu alaihi wa sallam) said: I had forbidden you to visit graves, now visit them as they make you pious in this world and remind you of the hereafter. (Jame' Tirmidhi, Hadith No. 974, Sunan Ibn Majah, Vol. 1, Pg. No. 112)
It has been narrated on the authority of Hadhrat Abu Hurairah (May Allah Ta'ala be well pleased with him) that the Holy Prophet (Sallallahu alaihi wa sallam) visited the grave of His mother…………… He (Sallallahu alaihi wa sallam) said: Visit graves, as they remind you of death. (Sahih Muslim, Vol. 1, Pg. No. 314; Sunan Ibn Majah, Vol. 1, Pg. No. 112)
It is narrated on the authority of Hadhrat Abu Sa'eed Khudri (May Allah Ta'ala be well pleased with him) that the Holy Prophet (Sallallahu alaihi wa sallam) said: I had forbidden you to visit graves. Now visit them, as there is warning and admonition in it. (At Targhib Wat Tarhib, Vol. 4, Pg. No. 357)
In the mentioned Hadith, 4 benefits of visiting graves have been mentioned:
1. Remind one of death.
2. Remind one of the hereafter.
3. Serve as a warning.
4. Make one pious.
Be it the graves of the common people or the graves of the Auliya, as per what the Holy Prophet (Sallallahu alaihi wa sallam) has said these 4 benefits are gained from all of them, but through visiting the graves of Auliya and the elders, the human being acquire piety, as benefits of the world and the hereafter are gained through them. For this reason, the Fuqaha (jurists) have clarified this in their works.