Short answer
Yes. The Prophet ﷺ said that no tiredness, illness, worry or grief befalls a Muslim, not even the prick of a thorn, except that Allah wipes away some of his sins by it. Illness is a test and a means of purification, not necessarily a punishment. The four schools agree, and seeking treatment does not lessen this reward.
Patience in illness is rewarded, and the illness itself expiates sins. It is permissible to tell a doctor or family about your pain and to make dua for a cure; what is blameworthy is complaining against Allah's decree.
The four schools agree on this.
Explanation
The hadith on this is clear: every hardship a Muslim feels, physical or emotional, down to a thorn's prick, is a cause for some of their sins to be removed. Another hadith adds that the believer's affair is all good. If something good happens he is grateful, and that is good for him; if harm befalls him he is patient, and that is good for him too.
Your good deeds also continue while you are ill. The Prophet ﷺ said that when a servant falls ill or travels, he is credited with the same deeds he used to do when healthy and at home. If illness stops you from fasting, praying at night or going to the mosque as you used to, the reward of those habits is still written for you.
Is illness a punishment? It can be a reminder, but it is not a sign that someone is worse than others. The prophets were tested the most: Ayyub endured years of illness and called on his Lord, "Adversity has touched me, and You are the Most Merciful of the merciful." So do not judge a sick person, and do not judge yourself harshly when you are ill.
What to do when you are ill:
- be patient, and make dua for a cure (see dua for health)
- seek treatment, which is Sunnah (see is medicine against tawakkul)
- pray as you are able, sitting or lying down if needed
Visiting the sick is a right Muslims owe each other; see dua for visiting the sick and the story of Prophet Ayyub.
The evidence
Quran, Surah Al-Baqara 2:155
وَلَنَبْلُوَنَّكُم بِشَىْءٍۢ مِّنَ ٱلْخَوْفِ وَٱلْجُوعِ وَنَقْصٍۢ مِّنَ ٱلْأَمْوَٰلِ وَٱلْأَنفُسِ وَٱلثَّمَرَٰتِ ۗ وَبَشِّرِ ٱلصَّٰبِرِينَ ﴿١٥٥﴾
And We will surely test you with something of fear and hunger and a loss of wealth and lives and fruits, but give good tidings to the patient,
Hardship, including illness, is a test from Allah.
Quran, Surah Al-Anbiyaa 21:83
۞ وَأَيُّوبَ إِذْ نَادَىٰ رَبَّهُۥٓ أَنِّى مَسَّنِىَ ٱلضُّرُّ وَأَنتَ أَرْحَمُ ٱلرَّٰحِمِينَ ﴿٨٣﴾
And [mention] Job, when he called to his Lord, "Indeed, adversity has touched me, and you are the Most Merciful of the merciful."
Ayyub's dua in long illness is the model of patient complaint to Allah.
Sahih al-Bukhari 5641
Sahih... ما يصيب المسلم من نصب ولا وصب ولا هم ولا حزن ...
"No tiredness, illness, worry or grief befalls a Muslim, even a thorn that pricks him, except that Allah wipes away some of his sins by it."
Illness expiates sins.
Sahih al-Bukhari 2996
Sahih... إذا مرض العبد أو سافر كتب له مثل ما كان يعمل مقيما صحيحا ...
"When a servant falls ill or travels, he is credited with the like of what he used to do when at home and healthy."
The reward of regular deeds continues during illness.
Sahih Muslim 2999
Sahih... عجبا لأمر المؤمن إن أمره كله خير ...
"How wonderful is the affair of the believer: all of it is good for him."
Patience in harm turns it into good.
This answer is pending review by the scholars on our team. Quran translation by Sahih International. Hadith Arabic from the standard editions of the six books and the Muwatta, with gradings as recorded there; the English is our own rendering. Spotted a mistake? Tell us.