Hadithcore
Mishkat al-Masabih, 1769

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.” Ibn Majah transmitted it.

وَعَنِ ابْنِ مَسْعُودٍ أَنَّ رَسُولَ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ قَالَ: «كُنْتُ نَهَيْتُكُمْ عَنْ زِيَارَةِ الْقُبُورِ فَزُورُوهَا فَإِنَّهَا تُزَهِّدُ فِي الدُّنْيَا وتذكر الْآخِرَة» . رَوَاهُ ابْن مَاجَه

References1 variant
In-Book Reference
Book 5, Hadith 241