The Prophet, peace and blessings of Allah be upon him, said,
“By the One in Whose hands is my soul, there is no decree that Allah determines for the believer except that it is good for him, and this only applies to the believer. If he meets with times of ease and plentitude, he thanks Allah and that is good for him. If he meets with times of adversity, he is patient and that is good for him.”
Therefore trial and tribulation is from the means of Allah aiding His servant, ennobling him and granting him well-being. It is for this reason that the most severely tried people were the Prophets, then those closest to them, each person being tried in accordance to his religion. The believer is afflicted with tribulation to such as extent that he ends up walking on the earth with no trace of sin remaining on him.
What the believer is afflicted of in this world, matters such as being defeated and overcome by his enemy, or being harmed by him, is something that is necessary and unavoidable, just like extreme heat and cold, illness, worries and distress. These matters are part and parcel of living in this world and having the nature that man does. Even children and animals face this as determined by the wisdom of the All-Wise. Were evil to be completely separated from good, benefit from harm, and delight from pain; this would be a totally different world lacking the all encompassing wisdom that has mingled these matters, now with the other. These matters, existing entirely on their own, are only to be found in another Abode,
“…so that Allah can sift the bad out from the good, and pile the bad on top of one another, heaping them all together, and tip them into Hell. They are lost.” (al-Anfal 8:37)
Trials and Tribulations: Wisdom and Benefits (Note that this extract is taken from Aid for the Yearning One in Resisting Shaytan) Imam ibn Qayyim al-Jawziyyah Pages 44-45