Starfleet is obviously a military. We've all seen it.
It is not, however, militaristic. Big difference.
Starfleet is a Military and also Militaristic.
It's just that it offers the insider's (true believer's) view of militarism, rather than the outsider's (the pejorative) view.
We are all now rather pious about the separation of church and state, but Trek is basically blind to separating the military and the state. The captain is an ambassador, negotiator, state-appointed prospector (they're always on the look out for those dilithium crystals and substances like ryetalyn), and military commander.
What makes the pill go down easily is that (1) we would all like to be autonomous and powerful (having these multiple jurisdictions of scientist, foreign lover, diplomat, explorer, etc.) like starship captains and (2) the show emphasizes the heroic nature of our heroic heroes so that we don't feel bad about the concentration of power. The prime directive (which is violated almost as often as it is invoked), for example, eases our consciences about the goodness of our good guys.
Just like Hornblower and Aubrey, Kirk and Picard are master and commander of the far side of the universe. Nick Meyer was not the first to observe that Trek is Hornblower-in-space, but he was quick to note that Trek had no qualms about militaristic solutions to problems.
Another consequence of having the military and state ride in the same boat is that...
Starfleet diplomacy is literally, gunboat diplomacy. True, Starfleet rarely
threatened "less developed" worlds with force if they didn't get their way (even though we've ofttimes seen them resort to force when such worlds fail to comply). And yet how many times have we seen the less advanced race feel the need to note that despite the pleasantries of the captain, his words still had a powerful ship backing them up. Who can blame them for thinking that they were engaging in a polite Melian dialogue? It's like the big boss asking you rather sweetly if you wouldn't mind giving him/her a ride home from work. There is no explicit threat if you say no and s/he might even explicitly state that it's no big deal if you say "No." Even so, how many people would nevertheless feel pressured to say "Yes"?
Starships serve two purposes. It exists to (1st) promote/defend the interests of the federation, and (2nd) to engage in scientific exploration (charting stars and observing alien species). The 2nd purpose, of course, is just one variety of the 1st (i.e., the federation is also interested in scientific exploration), and when science duties conflict with military duties, military duties come first. The position of a scientist (who is very often a starfleet officer) aboard a starfleet vessel, therefore, is not unlike that of the inquisitive of Dr. Marturin aboard the HMS Surprise.