What do you think? Every O-2 in the country is a constitutional lawyer?
As long as the chain of command remains intact, the military will follow the orders of their immediate superiors, unless and until it becomes clear that their immediate superiors are acting outside of the chain of command.
In a military coup, done right, they will never get to know that.
As a former O-1, O-2, and O-3, I disagree with your assessment. It is drilled into junior officers’ heads to consider whether an order is illegal. An order to depose the sitting President that does not come down from the appropriate civilian authority would be highly suspect, IMO.