John Adams was part of his cousin Sam’s long-term revolutionary strategy. Sam wanted tension between Bostonians and the occupying British. When the tension exploded into American deaths, he exploited them to the hilt.
At the same time, he wanted to show that Americans were not barbarous savages, and could uphold a civilized legal system, so cousin John was dispatched to defend the Brits. (John was happy to do so, from his own sense of principle, and from his love of controversy and unpopularity.) The conclusion is to be inferred from a post-trial election to fill a vacant seat in the Massachusetts House of Representatives: John ran, with Sam’s backing, and won. (He wasn’t that unpopular.)
Sam’s goal: to undermine British power, and to prepare Americans to set up their own parallel institutions.