Stupid writers, nothing more. Kirk's Starfleet was explicitly the military. Then Roddenberry changed his mind, and Picard spewed that drivel, and we've been stuck with that nonsense ever since.
Yes, I realize that, but too much of Star Trek has depended on that underlying subtext that we're stuck with it, especially now that JJ Abrams has elected not to change it. So we need some coherent way to rationalize it in-universe.
My rationalization is that Starfleet wasn't created to BE a military and was never intended to be used as one, but because the hazardous nature of their exploration mission necessitates having have the best ships, the best technology and the most effective and versatile weapon systems, the federation basically conscripts them en masse
whenever a fight breaks out.
Just to be clear: my PREFERENCE would be for Starfleet to play it straight, have it be evolved from the Air Force or a combination of Earth space programs (Roskosmos/NASA/Spaceguard etc) that got adopted by United Earth and then by the Federation as an expeditionary force chartered to locate new trade partners, new allies, new exploitable resources, etc. Alot would have to change for Starfleet to be depicted this way, though, and ST09 was on a trajectory in that direction until Scotty dropped the bomb on that idea in STID.