Military answers to whomever it thinks it's best to get paid. If relationship between government and the people fails so hard that collection of taxes to fund the military is threatened then the military sides either with the people and deposes the government or with the government and suppresses the unrest.
"the military" isn't a single entity. If things really got bad I suspect there would breaks all over the place as various groups (across all ranks) decide to either follow or refuse orders coming down. It would be chaos, the fact that things could get so bad that we're even talking about it is already a very bad sign.
I'm sure there's always some back and forth inside the structure of the military but since it's insular singular top down organization it's usually not visible to civilians and they only get exposed to the consensus that military eventually reaches. Since everybody in the military is armed there's very little benefit to actively fighting with each other using sizable force because it brings no one closer to ensuring getting paid. So any staunch opponents of consensus are just getting deposed or at most assassinated. Everything usually happens quite peacefully.