Sunan Ibn Majah, Volume 2, Book 6, Hadith 1571 (DarusSalam) ⓘ
It was narrated from Ibn Mas’ud that the Messenger of Allah said, “I used to forbid you to visit the graves, but now visit them, for they will draw your attention away from this world and remind you of the Hereafter.”
حَدَّثَنَا يُونُسُ بْنُ عَبْدِ الأَعْلَى، حَدَّثَنَا ابْنُ وَهْبٍ، أَنْبَأَنَا ابْنُ جُرَيْجٍ، عَنْ أَيُّوبَ بْنِ هَانِئٍ، عَنْ مَسْرُوقِ بْنِ الأَجْدَعِ، عَنِ ابْنِ مَسْعُودٍ، أَنَّ رَسُولَ اللَّهِ ـ صلى الله عليه وسلم ـ قَالَ " كُنْتُ نَهَيْتُكُمْ عَنْ زِيَارَةِ الْقُبُورِ فَزُورُوا الْقُبُورَ فَإِنَّهَا تُزَهِّدُ فِي الدُّنْيَا وَتُذَكِّرُ الآخِرَةَ " .
also referenced under: Hadith 1571 (Reference) & Book 6, Hadith 1638 (In-Book)