The Messenger of Allah ﷺ said, "I had previously forbidden you from visiting graves, but now visit them, for they instill detachment from this world and remind one of the hereafter."
حدثنا يونس بن عبد الأعلى حدثنا ابن وهب أنبأنا ابن جريج عن أيوب بن هانئ عن مسروق بن الأجدع
أن رسول الله ﷺ قال كنت نهيتكم عن زيارة القبور فزوروها فإنها تزهد في الدنيا وتذكر الآخرة
[Its chain of transmission is daif] Bayhaqi (4/77) and Hakim (1/375) narrated it from the hadith of Ibn Wahb, at length, and Busiri graded it sahih. Ayub is daif, as Ibn Main said. The hadith has corroborating narrations in Muslim and elsewhere, except for his saying, "for it makes one indifferent to this world," which has a corroborating narration in Bayhaqi and Hakim from the hadith of Anas , "for it softens the heart and brings tears to the eye." It is also found in Musnad Ahmad (3/250) from the hadith of Yahya bin Harith Taymi, from Amr bin Amir, from Anas.