The problem is not that Job had claimed to be righteous; but that he had done so in a way which suggests that God is unrighteous. Elihu is also correct in saying that Job had described God as his enemy. Job had done this more than once (Job 13:24; Job 19:11; Job 30:21) and even suggested that God had always been devising secret plans to harm him (Job 10:13–17).
10 Behold, he finds occasions against me, he counts me as his enemy,