The usual answer is legitimacy. The military can't seize power, if it's not loyal to its commanders. If people serve in the military due to personal loyalty and the promise of glory and loot, the military is a threat to the society. But institutions can create other purposes to serve, and then military commanders only have power if their actions are consistent with those purposes.