No traditional military had exploration or scientific research as one of its primary functions so far.
Not true. Exploration was widely seen as one of the primary missions of the various European militaries, especially the British Royal Navy, during the so-called "age of exploration." Heck, Lewis and Clark were U.S. Army officers.
The notion that exploration is not a military mission is based on a completely false understanding of military history and organization.
Well, I didn't say that no military ever participated in missions of exploration before. I was talking about the primary function of a military organization.
I doubt that you can say that the Royal Navy or the U.S. Army were specifically founded for the purpose of conducting exploration and research. I also doubt that they considered themselves to be scientific organizations as much as military organizations. I also doubt they had that many biologists, geologists, anthropologists, or sociologists among their officers.
In a sense, Starfleet could be opposite of traditional militaries. Old militaries were founded for the purpose of warfare and then send on missions of exploration when the need arised. Starfleet was founded for the purpose of exploration and then send on combat missions when the need arised.
I would also say that we can see Starfleet gradually evolve from a purely scientific organization into a more military-like organization during "Enterprise" because of the way the NX-01's mission unfolded. Several encounters with hostile species successively led to the installment of phase cannons ("Silent Enemy", 1x12), the introduction of the first "Tactical Alert" ("Singularity", 2x09), the upgrading to photonic torpedoes ("The Expanse", 2x26), the deployment of a MACO unit to the Enterprise ("The Expanse", 2x26), and the installment of a command center ("The Xindi", 3x01).
IIRC, Captain Archer was originally uncomfortable with most of these changes because he felt that this would make his mission and his ship too "military-like". However, in the end he always came to the conclusion that these changes were necessary. By the time of TOS, military tasks had probably become a regular part of Starfleet's duties.