He was human. Sure, he was the wisest man in history, and the Bible says that. But he wasn't Jesus. although it could be argued that Jesus was the wisest man in history, I mean, He was God.
Yeah, just like anyone, he was only a man. He went after many different women, and they caused him to go after foreign gods. We all do the same thing every single day, in a sense.
We always frown on the Israelites in the desert, claiming that they were pigheaded and dumb to disobey God like that. Yet, we are just the same, we do the same thing day after day.
Same reason if I gave you a hundred rules to make life long and happy and you memorised them all you'd still break them. We are human and rebellious, he rebelled against himself because he made the rules.