The Prophet ﷺ said, "No fatigue, illness, anxiety, sorrow, distress, or harm afflicts a Muslim, not even a thorn that pricks him, except that Allah wipes away some of his sins because of it."
حدثنا أبو عامر حدثنا زهير عن محمد بن عمرو بن حلحلة عن عطاء بن يسار
أن النبي ﷺ قال ما يصيب المرء المسلم من نصب ولا وصب ولا هم ولا حزن ولا غم ولا أذى حتى الشوكة يشاكها إلا كفر الله عنه بها من خطاياه
Its isnad is sahih, a repetition of 8014. It has also been narrated with the wording, "There is no calamity that befalls a Muslim except that Allah expiates for it, even a thorn that pricks him." Bukhari and Muslim narrated it from Ayesha, and Suyuti, may Allah have mercy on him, indicated its soundness in Al-Jami al-Saghir. Bukhari and Muslim also narrated, "There is no Muslim afflicted with a harm, whether a thorn or worse, except that Allah Most High removes his sins thereby, just as a tree sheds its leaves," from Ibn Masud.