The Nature of Magic Itself:
Magic is the ultimate expression of creativity. It defies repetition, commoditization, and control. It might derive from fae sources, or the stuff of chaos itself.
A wizard deprived of their free will or free expression will see their power decline quickly and, even despite specialization, be progressively less and less able to produce a desired result. What's more, it's inherently chaotic in nature, and has unpredictable results and/or side effects...ones that are generally manageable if the wizard himself or herself is free to "go with the flow", but makes it very difficult to reliably produce the identical magical effect for the 217th time when "your Majesty" commands.
The locals accept the wizard's eccentricities and the odd happenings because the wonderful things the wizard can do are worth it (and because the wizard usually stays in the tower well outside of the village). A ruler would be far less willing to accept these inconsistencies, unreliable results, and potential side effects...all for a power that becomes less and less useful the more it's ordered-up and commanded to be produced.
Now, SOME rulers will still get around this, but they'll do so by embracing the wonder of it and accepting the potential consequences...and they won't gain vast world-shaking power from doing so. This is why the governments that DO employ wizards do so not for the sake of controlling their power, but in the role of advisors and consultants who can occasionally do something directly useful.
Recent Memory/Consequences Too Dire:
Exactly the scenario that you bring up as why it would be bad...DID happen. Either in living memory (for some of those magic-scarred old veterans) or at the very least recently enough that everyone simply accepts that they're better off not mixing magic and politics.
If you want to tie both concepts together, then perhaps the immense amount of magical power unleashed in the "last war" damaged the nature of magic itself and made it fickle and unreliable, the way it is today.
In this scenario, there will still be visible, tangible evidences of the consequences of militarized magic in the land. Artifacts (maybe not of power...even just a warmage's uniform) will still exist in the setting. Locations will still be scarred, structures damaged or destroyed and never rebuilt, etc.
The Guild / Wizards Exist Outside the Law:
There is an over-arching association to which Wizards owe their ultimate loyalty, and it is a pledge that goes above and beyond nationality. Early users of the talent are ruthlessly sought, identified, and indoctrinated...and only when they thoroughly tow the wizarding guild's "party line" are they allowed out into an apprentice/master relationship for their true magic training and development.
Wizards are essentially empowered to do whatever they see fit, being "outside and above" the law, holding only one loyalty, to the guild, and one responsibility...the protection of humanity as a whole against threats beyond the capacity of men to face without magic. MOST wizards just accept this as a beneficial arrangement, survive their early indoctrination, and go about their business secure that they'll never have the local ruler make demands of them and the disastrous threat for which all wizardkind must remain vigilant...will never happen in their lifetime.
Only a select few are actively engaged in the maintenance of the guild itself, the indoctrination of new wizards, watching for that potential catastrophe someday, and realizing that their "deal" with all the rulers of the world is...at best...tenuous and not guaranteed tomorrow or next year. The whole law of wizardry is built upon a house of cards and some really theatrical bluffs that just might not really be a bluff after all.