Ambassador Sarek: As I recall, I opposed your enlistment in Starfleet. It is possible that judgment was incorrect. Your associates are people of good character.
Spock: They are my friends.
I remember waiting for Star Trek IV: The Undiscovered Country to come out. My friends and I speculated how they were going to get out of the jam of stealing the Enterprise, sabotaging the Excelsior, going into interdicted space, blowing up the Enterprise, killing the crew of a Klingon ship, and stealing that ship.
The most common theory was they would be kicked out of Starfleet but get to keep the Klingon ship similar to rolling a scout ship while mustering out in Traveller. Of course, like Traveller, they would be subject to recall and thus become a kind of Starfleet black ops group. While that would be a great rpg or action film it would be bad Star Trek.
Instead the crew loads up and heads for Earth to stand trial for their offenses.
A Lawful Good character typically acts with compassion, and always with honor and a sense of duty.
Clearly the crew of the Enterprise had acted with compassion and duty towards their friend. They also had a sense of honor and duty to the Federation. A man of duty and honor does not flee from his crimes but stands trial for them and fights for his vindication and receives his punishment.
Still, when the Earth is attacked by an alien probe we could excuse the crew for not going to Earth. They are going to stand trial not to be attacked by aliens. Yet each and every crew member was sworn to defend the Federation and thus has a duty to protect it. They are honor bound to stand by that duty. So, they risk their lives to save a planet which wants to put them on trial.
Federation Council president: Captain Spock, you do not stand accused.
Spock: Mister President, I stand with my shipmates.
After successfully saving the future does the crew demand that their actions allow the slate to be wiped clean? No, they still present themselves for trial.
And Spock, out of loyalty to the people who sacrificed for him chooses to stand trial with them.
So, next time you’re playing or dungeon mastering a paladin or other lawful good character and are running into the “good is stupid” or “good is dull and boring” or “good is inflexible” tap into the most successful crew in Starfleet for a model of lawful good behavior.