In this section of verses, we discover a return to the theme that life is not fair. There really isn’t a difference for the righteous and the wicked, because the fate of death awaits them all.
All we really know is that the righteous and their works are in the hands of God. However, we don’t know whether to expect good or bad things out of the life we will receive. We can’t know the future, but we can know the God who holds us in it.
The Teacher holds a rather pessimistic view in these verses. Because there is a common fate, the people hold more and more evil and madness in their hearts. Then all of humanity dies the same death. The only hope we have is while we are still alive. There appears to be no understanding of an afterlife that is taught in the New Testament here. This reflects the common view of the times and misses the teachings of the other places in the Old Testament that point to a life after death.