They need to protect themselves and their crews. Its only a coincidence that the weapons needed to take out an enemy ship's shields, weapons and engines and more if necessary are also able to cause that much damage to a planet. That isn't there intent.
Yeah, but that doesn't mean it's not a military. A military is not "any organization with the intent of starting a war."
A military is a state's armed forces. That's it. If a state goes to that organization to defend the state in a time of conflict, then that organization is its military. It's a legal status, not a value judgment or ideological statement.
Militaries can be large or small, powerful or weak. And they don't have to be militant or war-mongering. The Canadian Forces may be Canada's military, but I don't think anyone's ever accused the Canadian Forces of being particularly jingoistic.
And, yes, militaries are also often given other tasks. The United States Armed Forces were tasked with delivering humanitarian aide to Somalia in the early 1990s and to Indonesia in 2005. The Royal Navy often served as an exploratory agency and de facto diplomatic agency-slash-ad-hoc-mobile-Foreign-Ministry for the United Kingdom in centuries past. The US Navy to this day continues to use ships that conduct research missions.
And besides, Starfleet has been referred to as a military in the shows. Starfleet tries its officers in courts-martial. When the Federation President declares martial law, it's Starfleet that enforces it. When Leyton tried to overthrow the Federation government and establish himself as absolute ruler of the Federation, Sisko called the idea a "military dictatorship."
Starfleet is a military. It's just not militaristic.