Ecclesiastes 7:16-22 can help to solve the riddle of verse 15. To begin with, “Do not be overly righteousness” does not warn against aiming for excellence in obedience to God. Rather, it is a further caution not to find fault with God for allowing situations like those in verse 15 to exist, for such circumstances hold vital teaching for those directly involved.
Thus, this passage is first an appeal for humility, a caution against arrogant self-righteousness that guides a person to assert that he “knows it all,” that he fully grasps what is going on, and that his judgment is correct. The wisdom Solomon teaches here is that the goodness of the righteous must be accompanied by humility. Without the presence of humility, a person's goodness and righteousness run the risk of producing intellectual and moral pride.
This can be learned from the bad experiences of others whose examples are given in Scripture. The Pharisees became involved in such moral pride hundreds of years later. Jesus charged them with hypocrisy. In their self-righteousness, they were calling God into account because they believed His law was not enough. The Pharisees added their self-righteousness to God's written law by means of the spoken or oral law, a set of rules framed by the minds of men through the centuries. What a lack of humility! Their trashing of the written law was not wisdom, as Mark 7:6-9 shows.
Blinded by their proud self-righteousness, they could not see that, in their blind attempts to make up for what they perceived as God's deficiencies and the people's failures, they were adding despair to people's lives. Their judgment severely lacked a proper sense of proportion about what God requires.
An interesting sidelight is that the Bible shows that most Pharisees appear to have been well off. According to Jesus' judgment, they were far from righteous, so they actually fit the description of prosperous evil people given in Ecclesiastes 7:15.
But what the Pharisees were involved in is not the real lesson for a converted person, as the Pharisees were unconverted.
Psalm 73:1-17 vividly describes the emotional and spiritual involvement of a person caught in a paradoxical situation. This psalm depicts a righteous man for a time severely misjudging the reality of his situation until God reveals the truth. Any of us could be guilty of the same. The wicked appear to prosper only if we, in our judgment, consider only what appears on the surface.
What God reveals to the psalmist is that these people may appear to gain the whole world, but in reality, they are losing something of far greater value. The psalmist grasps this through prayer and meditation, and his emotional and spiritual state return to an even keel through God's revelation.
At one point, through a bad attitude toward God fueled by his envy of the worldly, the psalmist appears to have been rapidly sliding into despair and perhaps “right out of the church.” This presents a grave danger in such a paradoxical situation.
Assuming the psalmist was a converted man, what would have happened to him if he had not done the right thing and appealed to God, or if he appealed, but God did not respond as quickly as he expected? What if the trial had gone on and on without relief? From the psalmist's own testimony, as he went into the sanctuary, he was at the point that his feet had almost slipped. However, an answer on recognizing the issue appears within the psalm. Despite his envious attitude, the psalmist did not stop praying to God for understanding and relief. God has the answers.
When involved in such a scenario, we have in reality only three alternatives: One, we can continue as is, faithfully enduring with much prayer and steadfast submission to God's will. Two, we can give up in despair and leave the church. Three, we can strive all the harder to impress God by becoming super-righteous to attract His attention and receive blessings for our righteousness, relieving the stress. Solomon is addressing the third alternative in these eight verses.