I don't know much about the spanish war (french education has a lot to cover, and there's already a lot to talk about in the 1789-1815 era), but from what I understand Napoleon discarded his diplomats' warnings about the Bayonne meetings where he forced both contestants into abdication. He wanted a strong ruler in Spain to enforce the continental blocade against GB (Spain already being a strong ally of his), and decided to use the weakness of the two contestants to install someone he could trust. As Talleyrand feared, it led to revolts and eventual defeats. I'd say that he was blinded by the fact that similar tactics had worked in Naples, the NL etc, so he discarded the possibility that Spain would react negatively.
Overall, dude that got into power by doing bold powergrabbing moves thought doing bold powergrabbing moves always worked and lost all his power due to too many unsuccessfull bold powergrabbing moves.