The key distinction seems to be that David did not worship idols.
Solomon did not see that anything he had done was wrong and refused to repent even when God Himself rebuked him.
That takes a very special kind of stupid.
You can brush off rebukes from other people, even from prophets, but when God comes down and tells you that you are messing up most people would listen.