All perfect praise be to Allah, The Lord of the Worlds. I testify that none is worthy of worship except Allah and that Muhammad is His Slave and Messenger.
There are many wisdoms behind the afflictions that Allah decrees upon people. One of them is that they are means to expiate one’s sins of which he has not repented. Another is that they raise him in status and earn him greater rewards. If a person has sincerely repented of all his sins, then the wisdom behind the affliction that strikes him is to raise him in status and elevate him to higher ranks in the Sight of Allah, The Exalted. Perhaps he has a certain rank decreed for him by Allah, yet he cannot attain it by virtue of his good deeds alone; therefore, Allah, The Almighty, decrees such affliction for him to grant him that rank and status. The Prophet said: "A person would have a (high) rank with Allah which he cannot obtain by his deeds, so Allah continues to afflict him with things he dislikes until he reaches it." [Abu Ya'la and Ibn Hibbaan; Al-Albaani: Hasan (sound)]
For more benefit on the wisdom for Allah afflicting His Servants, please refer to Fataawa 87624 and 89110.
Allah Knows best.