The word "wisdom" doesn't mean what you think.
There are 2 kinds of wisdom: (1) from God, (2) from the wicked spiritual powers. Normally we think of the word wisdom as being of the first kind; certainly that wisdom spoken of in the book of Proverbs is of this type.
The word "wisdom" in this verse refers to the power of discernment, not to good judgment or the discernment of truth.
Solomon was wise but his wisdom failed him because it was incomplete. People were impressed by his wisdom but his holiness and judgment were lacking. Often, Solomon is presented as one who was wise, but who fell from grace. But based on the meaning of the word "wisdom", there is no reason we need to believe that he fell from grace at all — rather, he was never particularly holy or righteous. Early in his reign we have the following verse...
God granted true wisdom to Solomon...
[Solomon:] Give therefore thy servant an understanding heart to judge thy people, that I may discern between good and bad: for who is able to judge this thy so great a people? [The Lord:] Behold, I have done according to thy words: lo, I have given thee a wise and an understanding heart; so that there was none like thee before thee, neither after thee shall any arise like unto thee. (1 Kings 3:9,12)
But Solomon failed to remain true to his calling...
Solomon was able to compose wise sayings and write inspirational songs. Perhaps Martin Luther is right in claiming that our human wisdom is useless; that only our faith matters. Perhaps Solomon had human wisdom but lacked faith. It seems he grew weary of his songwriting and wisdom — perhaps it lacked the Spirit of God.
And his house where he dwelt had another court within the porch, which was of the like work. Solomon made also an house for Pharaoh's daughter, whom he had taken to wife, like unto this porch. (1 Kings 7:8)
At the same time that Solomon was building the temple he also had multiple wives. God kept reminding him to live a holy life during this time...
Concerning this house which thou art in building, if thou wilt walk in my statutes, and execute my judgments, and keep all my commandments to walk in them; then will I perform my word with thee, which I spake unto David thy father. (1 Kings 6:12)
Solomon was able to compose the most inspirational of speeches even while living in mortal sin. This reminds me of some Christian leaders who manage to hide their sin or who are just plain materialistic.
And he said, LORD God of Israel, there is no God like thee, in heaven above, or on earth beneath, who keepest covenant and mercy with thy servants that walk before thee with all their heart. (1 Kings 8:23)
Based on this word of the Lord, it is apparent that Solomon did not follow God's commands...
But if ye shall at all turn from following me, ye or your children, and will not keep my commandments and my statutes which I have set before you, but go and serve other gods, and worship them: Then will I cut off Israel out of the land which I have given them; and this house, which I have hallowed for my name, will I cast out of my sight; and Israel shall be a proverb and a byword among all people. (1 Kings 9:6,7)
In conclusion, the wisest man in the world was spiritually bankrupt. The wisest thing we can do is cling to the Lord and to call out to him for mercy continually.