One should not be hasty to disobey the king (or government), for he (and ultimately, God) will punish evildoers (Eccl. 8:3). And, when the king issues a command, his subjects do not have the right to question his judgment (8:4). If you are subject to the law of the land, you are wise to know that law and obey it (8:5).
Solomon affirmed in 8:6 - "For every matter there is a time and judgment". Both of these elements are significant (cf. 3:1ff). However, knowing the proper time and judgment is not always easy. It is so important that we trust God--the One who holds the future--since we often do not know what exactly the future holds. 8:8 teaches that authority cannot prevent death, and those who are given to evil will not be spared by it.
Ecclesiastes 8:9 states - "All this I have seen, and applied my heart to every work that is done under the sun: There is a time in which one man rules over another to his own hurt." Tragically, men often do not know how to exercise authority properly. It is possible to destroy yourself via the exercise of authority.
The theme appears to change in 8:10ff. The truth that death comes to all is underscored. Thus, we should enjoy life properly while we can. Solomon specifically affirmed that the wickedness evil men commit is often forgotten after their burial and not spoken out against. Consequently, the evil actions are repeated by others. The vain thing here is man's weak attitude against evil.
8:11 declares - "Because the sentence against an evil work is not executed speedily, therefore the heart of the sons of men is fully set in them to do evil." This is why people commit evil again and again. If governments would immediately punish wrong doers, crime would not be nearly as prevalent as it is today. Swift punishment is a deterrent to evil. It should be noted that the heart is where sin always originates (cf. Mark 7:21-23).
"Though a sinner does evil a hundred times, and his days are prolonged, yet I surely know that it will be well with those who fear God, who fear before Him" (Eccl. 8:12). With God in the picture, a life of sin is both empty and foolish in the ultimate sense. It is impossible for man, by his own power, to lengthen his days via wickedness.
8:14 reiterates the point of 7:15; that is, on Earth, the righteous man sometimes receives the punishment the wicked man deserves--and vice versa. These injustices will eventually be corrected. Solomon does not promote selfishness in 8:15. Rather, he encourages us to enjoy what God has blessed us with, despite all the evil, suffering, and struggles of this realm--remember, death comes to all.
The chapter closes with Solomon--the wise man of wise men--acknowledging that some things are beyond even his understanding. Specifically, it would seem that he had God's providential workings in mind. They are unknowable (Deut. 29:29), but we can and must trust the Lord, nevertheless (Rom. 8:28).