In TWOK, Carol Marcus reminds David that Starfleet has kept the peace for over one hundred years. So, keeping the peace is one of its duties. You need an armed force to keep the peace, so by definition, Starfleet is a military organization of some kind.
Although I agree with Starfleet=military, this isn't what that was supposed to mean.
Carol Marcus was talking about the military-vs-science debate, not literal peacekeeping duties.
From the script:-
DAVID: Every time we have dealings with Starfleet, I get nervous. ...We are dealing with something that could be perverted into a dreadful weapon. Remember that overgrown Boy Scout you used to hang around with? That's exactly the kind of man...
CAROL: Listen, kiddo, Jim Kirk was many things, but he was never a Boy Scout!
CAROL: Will you please be quiet! Commander Chekov, this is completely irregular.
CHEKOV (on viewscreen): I have my orders.
DAVID: Pin him down, Mother. Who gave the order?
CHEKOV (on viewscreen): The order comes from Admiral James T. Kirk.
DAVID: I knew it! I knew it! All along the military has wanted to get their han...
CAROL: This is completely improper, Commander Chekov. I have no intention of allowing Reliant or any other unauthorised personnel access to our work or materials.
CHEKOV (on viewscreen): I'm sorry that you feel that way, Doctor. Admiral Kirk's orders are confirmed.
AND THE EXCHANGE YOU REFER TO:-
CAROL (OC): We must have order here. This has to be some sort of mistake.
DAVID: Mistake? We're all alone here. They waited until everyone was on leave to do this. Reliant is supposed to be at our disposal, not vice-versa.
MADISON: It seems clear that Starfleet never intended that.
CAROL: I know that, but...
DAVID: I've tried to tell you before. Scientists have always been pawns of the military.
CAROL: Starfleet has kept the peace for a hundred years. I cannot and will not subscribe to your interpretation of this event.
JEDDA: You may be right, Doctor, but what about Reliant? She's on her way.
Starfleet is a military organisation, but has kept it's scientific responsibilities to the fore.
By the very nature of the Federation, the space military cannot conform to any known modern military organisation. They have all the trappings of the modern Navy, but their mission statement is totally different to today. It's closer to the Royal Navy of Captain Cook's time to the US Navy of USS Ronald Reagan.