God knew what he would do with all the wealth he was given, before He gave it to him.
I believe the purpose was to show all of mankind what happens when we have much of God's blessing, and begin to justify the things we do because we can pay for it.
It was the pagan wives that he allowed to come into the palace, that turned his head.
Remember those were the days that the Holy Spirit did not yet dwell in people as they do now, except at certain times.
At the end of Solomon's life, he saw the foolishness of his life and wrote a lot in teaching us to avoid attitudes and actions. He saw everything under the sun and called it all "vanity."
Next time we feel compelled to accuse our elders of their failings, perhaps we can remember Solomon and realize, all that he experienced taught him a lot and at the end of his life, he saw that all of it led to nothingness.
The conclusion was Ecclesiates 12:13;
"Let us hear the conclusion of the whole matter: Fear God, and keep his commandments: for this is the whole duty of man."
We do not really learn a lesson well without many failings and pratfalls, that teach us much.
Those that feel a need to protect continually those who are messing up, are missing the whole point of life, and that is to learn from everything we have to go through.
We can't learn without hurdles, they teach us what the inside really looks like. Our response to difficult things will show us our own heart and what needs prayer, that, as we confess our failings, God will do the work in us.
1 John 1:9 "If we confess our sins, he is faithful and just to forgive us our sins, and to cleanse us from all unrighteousness."
If we will not confess openly our failings, then God will have to keep bringing the same difficulties until we see them so clearly they can not be denied. Do we want to continually experience the same pratfalls over and over again? Isn't it better to admit and learn and go on to the next lesson?