At-Tirmidhi Related a similar narration on the authority of Al-Mughirah bin Shu’bah, and he added, "Thus you will be offending the living (i.e. if you curse their dead)."
وَعَنْ ابْنِ عَبَّاسٍ رَضِيَ اَللَّهُ عَنْهُمَا قَالَ: { مَرَّ رَسُولُ اَللَّهِ - صلى الله عليه وسلم -بِقُبُورِ اَلْمَدِينَةِ, فَأَقْبَلَ عَلَيْهِمْ بِوَجْهِهِ فَقَالَ:
"اَلسَّلَامُ عَلَيْكُمْ يَا أَهْلَ اَلْقُبُورِ, يَغْفِرُ اَللَّهُ لَنَا وَلَكُمْ, أَنْتُمْ سَلَفُنَا وَنَحْنُ بِالْأَثَرِ" } رَوَاهُ اَلتِّرْمِذِيُّ, وَقَالَ: حَسَن ٌ 1 .1 - ضعيف. رواه الترمذي ( 1053 ) وقال: حديث حسن غريب. قلت: وهذا الحديث ضعيف؛ لضعف سنده -وإن كان هناك ما يشهد له- خاصة وإن هذا الحديث فيه جملة منكرة.
Ibn ‘Abbas (RAA) narrated, ‘Once the Messenger of Allah (ﷺ) passed by some graves in Madinah. He turned his face toward them saying, “Peace be upon you, O dwellers of these graves. May Allah forgive you and us. You have preceded us, and we are following your trail." Related by At-Tirmidhi, who graded it as Hasan.
Sulaiman bin Buraidah narrated on the authority of his father (RAA) that the Prophet (ﷺ) taught us that when we visit graves we should say, “Peace be upon you, O believing men and women, O dwellers of this place. Certainly, Allah willing, we will join you. We supplicate to Allah to grant us and you well being.” Related by Muslim.