IMO this is another issue where canon is self-contradictory and that's just that. I seem to remember the Phil Farrand books discussing the matter and offering contradictory quotes from Kirk in various TOS episodes.
Maybe the best way to see it is that Starfleet are indeed the military, but they're not just
the military. They're NASA, the CDC, the EPA and probably Fish and Wildlife, too.
But character quotes come from a character point-of-view and can be wrong. Do we give more weight to those quotes than all the battles and other decidedly military missions we see Starfleet engage in on a rather regular basis?
Do they have other responsibilities outside of strict defense of the Federation? Yes. But so has pretty much every military in human history. Is the military no longer the military when they deliver humanitarian aid? Is the U.S. Army Corps of Engineers not the military?