Arguably, to me, a more interesting and complicated question than is Starfleet "a space military" is whether Starfleet is also supposed to be "the space police" for the Federation? The argument over Starfleet seems to break down over whether its role in exploration supersedes their duty as the organizing defense organization for the Federation.
But we also see Starfleet doing roles usually assigned to law enforcement (e.g., O'Brien's undercover work with the Orion Syndicate, the head of Starfleet's JAG office handles the case against Bashir's father, who's a civilian) and intelligence gathering.
This is an interesting question!
Re: "Honor Among Thieves." I don't think O'Brien's work infiltrating the Orion Syndicate
technically applies to the question of law enforcement, because the episode is not set on a Federation world. It's set on Farius Prime, an independent planet that stayed neutral during the Dominion War. So this would be an example of infiltrating an organized crime syndicate on foreign soil -- well within the remit of an espionage agency, especially since the goal in this instance was to determine if the Orion Syndicate was collaborating with the Dominion and/or would take action that would damage the Federation's war efforts.
Re: "Dr. Bashir, I Presume?" Yeah, that's always seemed pretty weird to me. One way to rationalize it might be to assume that Admiral Bennett made a deal with a Federation civilian prosecutor that they would agree to only seek a two-year rehabilitative penal colony sentence for Richard Bashir in return for Admiral Bennett agreeing not to pursue charges against Julian.
But, there is another thing to consider. In "Let He Who Is Without Sin...," Jadzia asserts that as a Starfleet officer, she has the authority to place under arrest those members of the New Essentialists Movement who had sabotaged Risa's weather control system. So that combined with Admiral Bennett in "Dr. Bashir, I Presume?" does suggest the possibility that Starfleet has some sort of civilian law enforcement authority. Personally, I don't like that idea at all and would prefer to assume that Bennett made a deal with a civilian prosecutor and that Jadzia was just talking out of her ass so as to intimidate the NEM members while making a citizen's arrest.
Here in the real-world, those duties are divided between the military and civilian authority (the FBI and CIA). So, in some ways, Starfleet concentrates powers that are divided at least in the United States between the Department of Defense, Department of Justice, and the Director of National Intelligence.
Well, yes and no. There is the
Defense Intelligence Agency, a major espionage agency that is a division of the Department of Defense rather than an independent agency like DNI/the CIA; it's the U.S.'s primary military intelligence organization. The
U.S. Intelligence Community also includes other military intelligence agencies that are divisions of specific U.S. military services, including the Office of Naval Intelligence (U.S. Navy), Marine Corps Intelligence (U.S. Marine Corps), the Military Intelligence Corps (U.S. Army), the Sixteenth Air Force (U.S. Air Force), and the National Space Intelligence Center (U.S. Space Force).
There are other countries that have a similar civilian foreign intelligence, military foreign intelligence, and domestic security service division as we see in the CIA, DIA, and FBI. In the Russian Federation, the
SVR serves as the primary civilian foreign intelligence agency, while the
GRU is their primary military intelligence agency and the
FSB is their primary internal security service. MI6 famously does civilian foreign intelligence and MI5 internal security, while
Defence Intelligence is their main military intelligence agency. The
BND is Germany's main civilian intelligence agency,
MAD does military counterintelligence, and the
BfV and
BPOL do internal security. (There's also signals intelligence, which is often its own separate agency -- the NSA in the U.S.,
GCHQ in the U.K.,
Spetssvyaz in Russia,
BSI in Germany, etc.)
I would equate Starfleet Intelligence to something like the U.S. Defense Intelligence Agency or British Defence Intelligence. Or, if you want to get
really strict in our legal analogies, maybe you'd want to compare S.I. to a division of a specific military service branch rather than to an agency within the Department of Defense like DIA. So maybe Starfleet Intelligence is to Starfleet as the Office of Naval Intelligence is to the U.S. Navy.
We do get the hint that Federation Security may serve the internal security role that organizations like the FBI or MI5 fulfill today. That does raise the question of whether the Federation has a non-Starfleet civilian intelligence agency and whether it has a signals intelligence agency.
The worldbuilding in Star Trek is very poor, though often times we see streamlined versions for narrative expediency. IE, the Homefront/Paradise Lost storyline on DS9 intentionally excluded and references to an Earth government or defense forces or security agencies mostly because the writers felt it would clog the script up with too much exposition and left the focus on the Federation government and Starfleet. A legitimate decision to make in the writer's room in the moment, sure, but in the scope of the greater franchise as a whole does create the impression that Starfleet has its hands in a bit too many pies.
I don't think the worldbuilding is
poor, but I agree that there are definitely areas of ambiguity as a result of the need for narrative efficiency when making a weekly one-hour television program, particularly back in the days when seasons were being written as they were being filmed.
Well, when I get hired by Subway, I don't swear a legally-binding oath to preserve, protect and defend the employee handbook....

Exactly. And Starfleet officers must take such an oath themselves, or else the Federation would have nobody it could legally compel to act in its defense in times of war.
Edit to add: And to be clear, the US Armed Forces do not create the rules they operate under. The Uniform Code of Military Justice was enacted by Congress and can only be changed by Congress. And the appeals process for the court system it uses end up at the same place as all the other appellate actions in the US—the Supreme Court.
We have no freaking idea where Starfleet gets its legal authority because its just TV fiction and that episode hasn't been written yet.
I mean, I think we can infer that the Federation Starfleet derives its authority from an Act of the Federation Council that has been signed by the Federation President. And we know from "Dr. Bashir, I Presume?" that the Federation Supreme Court possesses the authority of judicial review over Starfleet's ban on its officers being genetically augmented.