Where one might expect righteousness (as in a court), one finds iniquity. But Solomon cautions, "Hang on. God will judge." Another important point to understand is that God's plan seems designed to show men how weak and meaningless they are in the overall scheme of life.
Even injustice and wickedness serve a purpose. Though they are painful for us to deal with, they provide a massive demonstration of our ignorance of our own nature, clearly revealing the overall character of mankind without conversion.
This is a tremendous benefit to the converted because they can always look at the world and ask, "Do I want those results?" If what we see in the world motivates us to fear God and follow the path toward His Kingdom—even though it might be painful, cause us to make a great many sacrifices, or put us under some kind of persecution or tribulation—it is doing a positive work for us if it helps to keep us on the track.
If there were no benefit from it, God would not permit it. If we did not know what evil was, we could not repent. The world shows us, in lurid detail, what evil is. We have the opportunity to evaluate whether or not we want to do the things that have produced this world. Even in the courts, we will see evil, and we see it even in religion. Solomon says we should expect it and not be overly frustrated by it. Instead, we should learn from it.
John W. Ritenbaugh
Ecclesiastes and the Feast of Tabernacles (Part 2)