here's a source from the shaar bechina ch.5 of chovos halevavos regarding why children get sick. according to the marpe lenefesh commentary it also applies to adults too.
Later on he is subjected to illnesses and meets with painful incidents
so that he recognizes the world, and that its nature is not concealed
from him. Thus he is put on his guard against trusting in this world
thereby permitting his lusts to rule over him, in which case he would
become like the animals that neither think nor understand; as it is
written "Be ye not as the horse or as the mule which have no
understanding" (Tehilim 32:9).
(Tov Halevanon: "illnesses" - such as chicken pox and measles.
"painful incidents" - many weaknesses come in the boyhood years. PL -
accidents such as stepping on a metal nail. "Be ye not as the horse or
as the mule" - they need to be leashed and muzzled, so too man. The
painful incidents humble his lusts. "so that he recognizes the world"
- how a person's situation can change swiftly from contentment to pain so that he realizes not to trust in it and its tranquility - rather to
always be afraid and to seek refuge in G-d's shadow.
Marpe Lenefesh: If a human being had only constant good in this world,
he would forget and not recall the matters of his final end, and he
would trust (hope) in this world and follow the musings of his heart
and his lusts for all of his days. Therefore, it was among the divine
plan to send him sometimes bad illnesses, EVEN during his youth in
order that he recognize and know that there is no complete good in
this world. And even if he is in a very good situation, the bad
illnesses can come and ruin his joy, so that he won't trust in this
emphasis on the word "even" is mine
while there may be other reasons for specific cases, I think this is the most common one.