There were plenty of Roman soldiers who spent more time building roads and on other construction projects than they did fighting but they were still in the army. Scientific exploration, rescue operations, resupply missions, etc., etc., are things our current military does today. When a disaster strikes the United States, we send in the National Guard to rescue people, distrbute food/supplies, and to help make critical repairs.
Kirk was sent to a courts martial for allegedly failing in his duty during a scientific mission. Kirk was prosecuted by a military officer, judged by a panel of captains, and they make it a point to let us know his lawyer was actually a civilian. The idea that Starfleet wasn't a military organization didn't pop up until after the series ended and it's because Roddenberry went off the deep end. TNG only improved when Roddenberry's influence began to wane.