Starfleet's first mission is "to seek out new lifeforms and new civilizations" etc. However, there's the unpleasant fact that some new life and new civilizations don't WANT to be interfered with or even contacted. Exploration is all well and good, but one must be prepared to defend oneself. If not, civilizations like the Klingon Empire, the Romulan Star Empire, the Cardassian Union, the Tholian Assembly, the Dominion, and the Borg Collective would've been picking the Federation's bones from their teeth a long time ago. Starfleet may not be a "military" organization, but they have to be prepared for that eventuality.
I know it's sort of wrong to compare Star Trek to Star Wars, but Starfleet is similar in some ways to the Jedi of the Old Republic. Exploration and diplomacy first, use force only when all other options are exhausted. And, like the Jedi during the Clone Wars, Starfleet is not a military organization unless every option has been exhausted and the entire Federation is under threat. That's the only time I ever disagree with Gene Roddenberry's "There should be no war ever" philosophy as it applies to Star Trek's universe. There won't always be all powerful Organians to stop the fighting. There will, however, always be races with an inexorable desire for conquest. Honestly, if they wanted to keep the "no war ever" philosophy intact, then the Borg should have never been introduced. The Borg, IMO, was the beginning of the end of Gene's ideal. As such a dangerous, inexorable, unstoppable, and downright relentless force, eventually they would have brought everything to bear on the Federation(which they finally did in the novels). That opened the doors for concepts such as the Dominion, Species 8472, and the Hirogen, all incredibly tenacious and hell-bent on destruction.