Ibn Mas'ud reported God’s messenger as saying, “I forbade you to visit graves, but you may now visit them, for they produce abstinence in this world and act as a reminder of the next.”
Muhammad b. an-Nu‘man who traced the tradition back to the Prophet reported him as saying, “If anyone visits the grave of his parents, or of one of them, every Friday he will be granted forgiveness and it will be recorded as filial piety.”
Baihaqi transmitted it in mursal form in Shu'ab al-iman.
Abu Huraira said God's messenger cursed women who visited graves.
Ahmad, Tirmidhi and Ibn Majah transmitted it, Tirmidhi saying this is a hasan sahih tradition. He added that some learned men consider this was before the Prophet gave licence to visit graves, and when he gave it both men and women were included. But some hold that he disapproved of women visiting graves because of the small amount of self-control they possess and their tendency to be greatly upset. The quotation from him ends here.
She said she asked God’s messenger what she should say, i.e. when visiting graves, and he told her to say, “Peace be upon the inhabitants of the abodes, believers and Muslims, and God show mercy to those of us who go before and those who go later. If God will we shall join you."