كتاب البر والصلة والآداب
45  
The Book of Virtue, Enjoining Good Manners, and Joining of the Ties of Kinship
(25)
Chapter: Whomever Is Cursed, Reviled Or Prayed Against By The Prophet (SAW) When He Does Not Deserve That, It Will Be Purification, Reward And Mercy For Him
(25)
باب مَنْ لَعَنَهُ النَّبِيُّ صلى الله عليه وسلم أَوْ سَبَّهُ أَوْ دَعَا عَلَيْهِ
Sahih Muslim 2601 b

Abu Huraira reported Allah's Apostle (ﷺ) as saying:

O Allah, I make a covenant with Thee against which Thou wouldst never go. I am a human being and thus for a Muslim whom I give any harm or whom I scold or upon whom I invoke curse or whom I beat, make this a source of blessing, purification and nearness to Thee on the Day of Resurrection.
حَدَّثَنَا قُتَيْبَةُ بْنُ سَعِيدٍ، حَدَّثَنَا الْمُغِيرَةُ، - يَعْنِي ابْنَ عَبْدِ الرَّحْمَنِ الْحِزَامِيَّ - عَنْ أَبِي الزِّنَادِ، عَنِ الأَعْرَجِ، عَنْ أَبِي هُرَيْرَةَ، أَنَّ النَّبِيَّ صلى الله عليه وسلم قَالَ ‏ "‏ اللَّهُمَّ إِنِّي أَتَّخِذُ عِنْدَكَ عَهْدًا لَنْ تُخْلِفَنِيهِ فَإِنَّمَا أَنَا بَشَرٌ فَأَىُّ الْمُؤْمِنِينَ آذَيْتُهُ شَتَمْتُهُ لَعَنْتُهُ جَلَدْتُهُ فَاجْعَلْهَا لَهُ صَلاَةً وَزَكَاةً وَقُرْبَةً تُقَرِّبُهُ بِهَا إِلَيْكَ يَوْمَ الْقِيَامَةِ ‏"‏ ‏.‏
Reference : Sahih Muslim 2601b
In-book reference : Book 45, Hadith 117
USC-MSA web (English) reference : Book 32, Hadith 6290
  (deprecated numbering scheme)