Allah is just. However, Allah's justice crosses this world and the next. When we are suffering, there is an aspect due to fate or what Allah has decreed, there is aspect due to Allah's testing people, there is an aspect due to divine punishment, and there is an aspect due to free will and bringing things upon ourselves.
It is often asked why people who are faithless, immoral, or even evil sometimes seem to flourish in this world, whereas oftentimes those who are faithful or good suffer.
First, Allah responds to what people genuinely want and seek (even if people are wrongdoers). Some people only want worldly enjoyment or position even if it harms others, and they attain that. However, as a natural cause and effect relationship, it causes them misery in the afterlife. In fact, it often causes them misery in this life. It is not uncommon for the world's elite to suffer from drug addiction, suicide, anxiety, and the like. Those who acquire wealth by force often have no rest and sometimes even have had to physically move from place to place to avoid being killed. We reap what we sow, even if it takes time.
Personally, the older I get, the more I have seen divine justice enacted upon people in this life, even if it was in cases where I never expected to see it.
In fact, when Allah no longer extends mercy to a person, Allah allows them to do whatever they like in this life, because they reap misery for themselves. This is a form of divine curse or an expression of divine hatred.
Conversely, Allah tries the believers more out of His love, because going through difficulty develops us. This doesn't mean that we should seek difficulty or act helpless and remain in it out of faith - we are meant to strive - but rather that wisdom, compassion, and reliance of God are often born from the challenges we face, not the easy times. Sometimes the darkest times can also be the ones when we see the most light. It is said that the trials of God are like gifts to the believer. It is also said that there are some levels of faith that can only be reached by severe trials such as severe illness.
When a person earns divine punishment, and it will not be forgiven or redressed by intercession, they are punished either in this life or in the next. If we are punished in this life, it will have been a blessing because the punishment in the next is far worse. This is one of the reasons the punishment for the truly evil is saved for the next world. It is narrated that if a believer has sins that require punishment and cannot be erased, Allah will sometimes give that believer a difficult death (that is, a difficult time for the soul to leave the body on its eternal journey) as expiation.
That being said, often what comes across as "punishment" is simply the natural cause of wrong acts, and wrongdoers also suffer the natural consequences of wrong acts in this life. As a very simple example, just to demonstrate the point, an alcoholic is more likely to have marriage problems, get into an accident, harm their health, suffer financial loss, and so forth. This doesn't even need to be ascribed to divine punishment, it is cause and effect, and this is why alcohol is forbidden in Islamic law. It is also important to remember that not all suffering is divine punishment.
Second, we as humans also have free will. Free will is on an individual and social level. The relationship between fate and free will is complicated. In many cases, suffering is caused not by an individual decision but rather by social or political decisions. Allah allocates sustenance to everyone in varying amounts; but when someone is suffering from severe poverty, someone has stolen that sustenance. In this day and age that happens on an individual and mass level eg through inherited social class, nationality and the resources or opportunities it conveys, access to education, institutionalized racism or the acts of major multinational corporations.
There are also laws of cause and effect. Sometimes there is also responsibility on a people as a whole, e.g. a people who accept tyranny in their personal lives, family lives, or communities will also be more likely to accept political tyranny. A people who do not do genuine amr bil marouf (calling to what is good) for issues of social justice and so forth will also suffer from that. These things are mentioned in hadith. It is sad but fair to say that a lot of the suffering in the Muslim-majority world today is not due to lack of resources or individual faults but rather due to political corruption, mismanagement, greed among the elite, and the like. Of course one can also lay blame on things such as colonialism or post-colonialism which led to this or continue to prop up injustice and dictatorships, but at the end of the day we are the only ones who can lift ourselves up.
This is largely more of a modern issue with respect to the Muslim-majority world as in previous centuries the Muslim world was in a much better condition, economically and politically. It is really only in the 19th-20th century that the West skyrocketed to material, technological, and political ascendancy, and this left many Muslims wondering for the first time what had gone wrong or if indeed there was something wrong with Islam itself.
One thing to consider is that, in the past, among Muslims it was common for both the elite and the poor to adhere to Islam and to value faith. Even tyrants gave Islam lip service. However, in the 20th century, a chunk of the financial and political elite in the Muslim world went towards secularization and away from the open practice of Islam, and this gives the impression that somehow being rich or powerful and being unreligious go together. The same can be said about religion in general in the West. However this also is really a modern thing and has not been the case throughout history.
In any case, we as humans need to get our act together; when we can work in unison for the greater good, we are likely for flourish. This is true for the faithful and this is true for the faithless. It is true for the Muslim and it is true for the person of any other faith.
In short, Islam teaches us to work for the well-being of ourselves and others in this life, and in the next. There is no merit to suffering for the sake of suffering. Many times people attribute their suffering to Allah or fate whereas they really could have done something to change their circumstances but were afraid to or psychologically unable to make the shift. We should use whatever resources we have (inner, outer, psychological, practical, spiritual) to uplift ourselves and others. We can and should also pray that Allah provides sustenance, ease, health, or whatever it is that we need.
Also it is good to remember that many faithful and ethical people do quite well financially and materially! So not everyone is suffering. But it is a good question to address.