There are a number of reasons why God allows hardship and adversity to befall the human. Even the genuine believers experience hardship and adversity at some stage in their lives in accordance to God’s wisdom and God’s plan:

1- Test of Faith

It is God’s design to put the human through hardship and adversity so as to test their faith and their resolve and trust in God:

Do the people think that they will be left to say, “We believe,” without being put to the test? (Quran 29:2) We have tested those before them, for God must distinguish those who are truthful, and He must expose the liars. (29:3)

Also:

We will surely test you through some fear, hunger, and loss of money, lives, and crops. Give good news to the steadfast. (2:155)

To pass the test, the believer must maintain his trust that God only can relieve his hardship. The believer will maintain his prayer and call onto God:

Who is the One who rescues those who become desperate and call upon Him, relieves adversity, and makes you inheritors of the earth? Is it another god with God? Rarely do you take heed. (27:62)

2- Cleansing our Soul

Hardship and adversity is decreed by God as a cleansing of our souls from sins we have already committed. As a result, some of the bad things that happen to us are a direct result of sins we have committed:

Anything bad that happens to you is a consequence of your own deeds, and He overlooks many (of your sins). (42:30)

The concept of cleansing the human from sins in this life is a Quranic truth. It can be achieved through the experiencing of hardship and adversity (as 42:30), and it can also be through the payment of a “sadaqa” (charity) for the specific reason of cleansing the soul from sins which have been committed:

Take from their money a ‘sadaqa’ (charity) to purify and sanctify them. And encourage them, for your encouragement reassures them. God is Hearer, Omniscient. (9:103)

3- Gratefulness

Suffering through hardship and adversity is a reminder for people who tend to take things for granted and forget all of God’s blessings. Despite all the blessings given to the human by God, the human being is unappreciative. A little reminder in the shape of hardship or adversity may hopefully do the job of teaching the human not to take God’s blessings for granted:

If you count God’s blessings, you can never encompass them. Indeed, the human being is transgressing, unappreciative. (14:34) When we bless the human being, he turns away, and drifts farther and farther away, and when he suffers any affliction, he implores loudly. (41:51)

4- Remembering God

Adversity and hardship is also a very effective reminder for those who are too much absorbed in the worldly life, and thus they may not be as devoted to God as they should be. Due to their being too preoccupied with this worldly life they do not seek God nor call on God as they should:

He is the One who moves you across the land and sea. You get onto the ships, and they sail smoothly in a nice breeze. Then, while rejoicing therein, violent wind blows, and the waves surround them from every side. This is when they implore God, sincerely devoting their prayers to Him alone: “If You only save us this time, we will be eternally appreciative. (10:22) But as soon as He saves them, they transgress on earth, and oppose the truth. O people, your transgression is only to the detriment of your own souls. You remain preoccupied with this worldly life, then to us is your ultimate return, then we inform you of everything you had done. (10:23)

5- God’s Power and Authority

Many people are either oblivious of, or need to be reminded of God’s absolute authority. Hardship and adversity are one way to remind them that no one can save them but God, and also remind them of God’s absolute authority. They also need to be reminded that they need God in every minute of their lives. Sadly when God relieves the adversity, many of them return to idol worship once again:

O people, you are the ones who need God, while God is in no need for anyone, the Most Praiseworthy. (35:15) If the human is touched by adversity, he implores us, but as soon as we bestow a blessing upon him, he says, “I attained this because of my cleverness!” Indeed, this is only a test, but most of them do not know. (39:49) When adversity touches the human being, he implores us while lying down, or sitting, or standing up. But as soon as we relieve his adversity, he goes on as if he never implored us to relieve any hardship! The works of the transgressors are thus adorned in their eyes. (10:12) When the human being is afflicted, he implores his Lord, sincerely devoted to Him. But as soon as He blesses him, he forgets his previous imploring, sets up idols to rank with GOD and to divert others from His path. Say, “Enjoy your disbelief temporarily; you have incurred the hellfire.” (39:8) When adversity afflicts the people, they turn to their Lord, totally devoting themselves to Him. But then, as soon as He showers them with mercy, some of them revert to idol worship. (30:33)

Source: http://www.quranislam.