Well first in a simple sense, the way in which Allah made things is that Allah made life going around with cause and effect for every action has it consequence. So many times what we may view as suffering is actually because of the person's on the nation's own actions for this is how the world goes.
Another reason can be explained by the famous saying " what goes around comes around". The Islamic version on that is you would get the same as you did.
Here are some verses that would show that in the Quraan
24:22 And let not those of virtue among you and wealth swear not to give [aid] to their relatives and the needy and the emigrants for the cause of Allah , and let them pardon and overlook. Would you not like that Allah should forgive you? And Allah is Forgiving and Merciful.
40:42 And the retribution for an evil act is an evil one like it, but whoever pardons and makes reconciliation - his reward is [due] from Allah . Indeed, He does not like wrongdoers.
64:14 O you who have believed, indeed, among your wives and your children are enemies to you, so beware of them. But if you pardon and overlook and forgive - then indeed, Allah is Forgiving and Merciful.
2:40 O Children of Israel, remember My favor which I have bestowed upon you and fulfill My covenant [upon you] that I will fulfill your covenant [from Me], and be afraid of [only] Me.
47:7 O you who have believed, if you support Allah , He will support you and plant firmly your feet.
2- Another reason for the suffering is that it would be a test for people and the believers
29:2 [29:2] Do the people think that they will be left to say, "We believe," without being put to the test?
[29:3] We have tested those before them, for God must distinguish those who are truthful, and He must expose the liars.
also:
[2:155] We will surely test you through some fear, hunger, and loss of money, lives, and crops. Give good news to the steadfast.
3- Another reason is that Allah is reminding people to turn back into Him. Although some people do the opposite, but some people turn back to Allah only in certain conditions
[14:34] If you count God's blessings, you can never encompass them. Indeed, the human being is transgressing, unappreciative.
[41:51] When we bless the human being, he turns away, and drifts farther and farther away, and when he suffers any affliction, he implores loudly.
[10:23] 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.
4- Better ranking in heaven because of patience. Patience is one of the keys of the heaven and it is highly rewarded in Islam.
2:45 Nay, seek (Allah's) help with patient perseverance and prayer: It is indeed hard, except to those who bring a lowly spirit,-
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,
3:200 O you who believe! Endure and be more patient (than your enemy), and guard your territory by stationing army units permanently at the places from where the enemy can attack you, and fear Allah, so that you may be successful.
If you look into Islam, you will notice that prophets were actually people who suffered the most in this life and they are the ones who have the highest rewards in the second life.
5- Also, sometimes people get punished in this life rather than getting punished on the judgement day for that punishment would be better. If you ask many muslims would they like to be punished now or on the day of Judgement they would say we would prefer to be punished in this life.
Finally we have to know that according to Islam this life is only a test for us and that every single deed and action we would be held accountable for.
6:32 And the worldly life is not but amusement and diversion; but the home of the Hereafter is best for those who fear Allah , so will yo
8:46 Wealth and children are [but] adornment of the worldly life. But the enduring good deeds are better to your Lord for reward and better for [one's] hope.
Also we should know that Allah will not do injustice to anyone.
99:6-9
6 That Day, the people will depart separated [into categories] to be shown [the result of] their deeds.
7 So whoever does an atom's weight of good will see it,
8 And whoever does an atom's weight of evil will see it.