Anas reported: The Messenger of Allah, peace and blessings be upon him, said, “I had prohibited you from visiting the graves, but it occurred to me that now you may visit them. Verily, they soften the heart, shed tears in the eyes, and remind of the Hereafter. Thus, visit them and do not say anything obscene.”
Source: al-Sunan al-Kubrá lil-Bayhaqī 7198
Grade: Sahih (authentic) according to Al-Albani
عَنْ أَنَسٍ قَالَ قَالَ رَسُولُ اللهِ صَلَّى اللهُ عَلَيْهِ وَسَلَّمَ كُنْتُ نَهَيْتُكُمْ عَنْ زِيَارَةِ الْقُبُورِ ثُمَّ بَدَا لِي فَزُورُوهَا فَإِنَّهَا تُرِقُّ الْقَلْبَ وَتُدْمِعُ الْعَيْنَ وَتُذَكِّرُ الْآخِرَةَ فَزُورُوا وَلَا تَقُولُوا هُجْرًا
7198 السنن الكبرى للبيهقي كتاب الجنائز جماع أبواب البكاء على الميت باب زيارة القبور
4584 المحدث الألباني خلاصة حكم المحدث صحيح في صحيح الجامع