Anas bin Malik reported,

The Messenger of Allah ﷺ said, "When Allah tests a Muslim servant with an affliction in his body, Allah says, 'Record for him the righteous deeds he used to perform.' If He restores him to health, He washes him clean and purifies him, and if He takes his soul, He forgives him and shows him mercy."

Azami 3390

Hasan

عن أنس قال

قال رسول الله ﷺ: إذا ابتلى الله العبد المسلم ببلاء في جسده، قال الله: اكتب له صالح عمله الذي كان يعمله، فإن شفاه غسله وطهره، وإن قبضه غفر له ورحمه.

الأعظمي 3390حسن
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Patience in tribulation and illness
Section
Sick and the traveler are credited with what they used to do while resident and healthy
Numbering
Jami al-Kamil 3390 (2nd edition)
Azami 3390