رِيَاضُ الصَّالِحِينَ
Riyad as-Salihin 583
The Book of Miscellany
Desirability of visiting the Graves for men, and that they should say
وَعَنِ ابْنِ عَبَّاسٍ رَضِيَ اللَّهُ عَنْهُمَا، قَالَ مَرَّ رَسُولُ اللَّهِ صَلَّى اللَّه عَلَيْهِ وَسَلَّمَ بِقُبُورِ بِالْمَدِينَةِ فَأَقْبَلَ عَلَيْهِمْ بِوَجْهِهِ فَقَالَ: “السَّلَامُ عَلَيْكُمْ يَا أَهْلَ الْقُبُورِ، يَغْفِرُ اللَّهُ لَنَا وَلَكُمْ أَنْتُمْ سَلَفُنَا وَنَحْنُ بِالْأَثَرِ” ((رَوَاهُ التِّرْمِذِيُّ وَقَالَ: حَدِيث حَسَن)).
Ibn 'Abbas (May Allah be pleased with them) reported: Messenger of Allah (ﷺ) passed by the graves at Al-Madinah. He turned his face towards them and said, "May you be granted safety, O inmates of the graves. May Allah forgive us and you. You have preceded us, and we are to follow." [At-Tirmidhi, who classified it as Hadith Hasan].
Riyad as-Salihin, 583