When you don't look beyond this world, it seems like justice will never prevail. Then it may appear that certain people in this world will never receive the punishment they deserve. If you only look at this life and world, you will always remain sceptical.
Solomon gives us God's answer in this verse. He knows that God's righteous judgment will one day come upon every person. The Lord comes with his judgment in his time. At the final judgment it will become clear that the Righteous One, the King of kings, will forever rule and conquer. His justice is impartial, fair and just. Those who are treated unjustly in this world and find no justice, may know that one day the just judgment will be pronounced.
In this confidence, the Lord Jesus allowed himself to be treated unjustly. No one has felt injustice as intensely as he did. Yet he continues to rely and trust on his Father in heaven. He knows that the day of righteous judgment will come, also for those who condemned him. We read about this in 1 Peter 2:23: When he was reviled, he did not revile in return; when he suffered, he did not threaten, but continued entrusting himself to him who judges justly.
17 I said in my heart, God will judge the righteous and the wicked, for there is a time for every matter and for every work.