Captain James T. Kirk is known for taking risks in Star Trek, but his circumvention of Starfleet regulations has occasionally resulted in Kirk facing a court-martial. Described in Star Trek (2009) as "a peacekeeping and humanitarian armada," a force for good, Starfleet Officers are held to a high standard of duty and honor while maintaining a hierarchical authority. With multiple instances of Starfleet Officers – and even Captains – facing court-martial throughout Star Trek’s half-century history, Starfleet occasionally navigates conflicting moralities or agendas to maintain a high standard of excellence, order, and peaceful service.
https://screenrant.com/captain-kirk-court-martialed-in-star-trek-why/