The Messenger of Allah ﷺ said, "I had previously forbidden you from visiting graves. Now visit them, for they soften the heart, bring tears to the eye, and remind one of the Hereafter. But do not utter improper speech."
قال رسول الله ﷺ: كنت نهيتكم عن زيارة القبور، ألا فزوروها فإنه يرق القلب، وتدمع العين، وتذكر الآخرة، ولا تقولوا هجرا.
Hakim narrated it (1/376) with his chain from Amir bin Yasaf, who said, Ibrahim bin Tahman narrated to us, from Yahya bin Abbad, from Anas, and he mentioned it. Its chain is hasan because of Amir bin Yasaf, for he is "Salih" as Abu Hatim said. Dhahabi said, It was also narrated with another chain from Anas. I say, What I have mentioned is the best of them. Imam Ahmad narrated it (13487) from Yaqub, who said, My father narrated to us, from Ibn Ishaq, Yahya bin Harith Jabir narrated to me, from Abdul-Warith the freedman of Anas and Amr bin Amir, both of them from Anas, who said, "The Messenger of Allah ﷺ forbade visiting graves, eating the meat of sacrificial animals after three days, and making nabidh in gourds, hollowed-out logs, glazed jars, and tar-coated vessels."He said, Then the Messenger of Allah ﷺ later said, "Indeed, I had forbidden you three things, but it has now become clear to me otherwise regarding them. I forbade you to visit graves, but it has become clear to me that this softens the heart, brings tears to the eye, and reminds one of the hereafter, so visit them, but do not say anything improper. I forbade you to eat the meat of sacrificial animals beyond three nights, but it has become clear to me that people give gifts to their guests and set aside portions for those who are absent, so keep as much as you wish. I forbade you to make nabidh in these vessels, so drink from whatever you wish, but do not drink anything intoxicating. Whoever wishes may tie the neck of his waterskin, sealing in sin."Hakim also narrated it (1/376) through the route of Yahya bin Abdullah Taymi, from Amr bin Amir Ansari alone, from Anas, in abridged form.In the chain is Yahya bin Harith, who is Yahya bin Abdullah bin Harith Jabir. Most scholars declared him daif. Imam Ahmad said, There is no harm in him. Ibn Adi said, I hope there is no harm in him. Hafiz classified him as "layyin al-hadith" (weak in hadith transmission). The hadith has other chains that are even weaker than the one I have mentioned.His statement, "do not say anything improper," means do not utter foul speech such as "woe unto me" or similar expressions.