Solomon says that sometimes the righteous suffer while the wicked prosper. In this, he encapsulates the book of Job which gives a glimpse into the workings of Heaven.