Also leaders tend to keep each other in check and are constantly being reviewed. If you're a bad leader in the military it is typically immediately apparent and gets changed at some point. Additionally, leaders are also in turn managed by other leaders.
You're also not guaranteed promoted just because of your time-in-grade, especially not for higher ranks (e.g. E-5 and above). You also can't just transfer into the military with a high rank, meaning you have to work earn it and work your way up. It's not a full-proof system of course, but it does a great job. If you forced me to call out one exception, I would consider the officer path to be a shortcut to leadership, though they are typically required to go to college and extra training. But clearly, they don't have the military time-in-grade. But you're day-to-day is not really ran by officers, so it's not quite as relevant. (I'm speaking for the Marine Corps leadership as that's all I know first-hand.)