Because the Starfleet Academy graduates are lawyers
This is a strange conclusion, but it is logically necessitated by the events of the TNG episode "The Drumhead", when Admiral Satie and her investigating team accuse Crewman Simon Tarses of betraying the Federation.
The magnitude of the legal trouble Mr. Tarses was in cannot be overstated; it is analogous to having a senior US Attorney and the FBI accusing an American of treason.
We know from Picard's actions and words in the episode that he is deeply concerned about preserving the rights guaranteed by the Federation Constitution, and will not allow Admiral Satie to step over them. We also know from this episode that there is an apparent right to counsel (like that guaranteed by the ECHR and the US Constitution) in the Federation.
Given that Picard is eager to protect Tarses's fundamental rights as an accused person, and also given that Picard is smart enough to know that someone in Tarses's position is in so much legal trouble that they especially need a laywer, we can infer that he would not accept shortcuts or workarounds for Tarses's rights. The whole thrust of the episode is Picard defending rights against a McCarthy-esque witchhunt, after all.
Therefore, we can reasonably infer that Picard would not have allowed Tarses to be represented by an amateur or unqualified person, since doing so would vitiate the entire point of having a right to counsel. Why then, was Picard content to have Riker be the defense attorney, rather than insisting the Enterprise ditch to the nearest Starbase or set up a subspace relay?
There are two possible answers: either Picard does not care that much about the content of fundamental rights, or Riker is a qualified lawyer. The former seems absurd, leading one inevitably to the latter. The conclusion must be that Starfleet Academy graduates are lawyers.
To our perspective, this can seem bizarre, but recall that Starfleet Academy graduates can pilot a shuttle, fix just about anything, perform field medical treatment, engage in diplomacy, speak Latin, and do about a million other things that are discrete specialties in our time. Is it really so strange that an academy that teaches its graduates to repair supercomputers and the ancient archaeology of obscure planets also teaches them law? (It probably also helps that better medical technology has improved human lifespans) Just like there are specialized navigators in Starfleet, but any crew member can navigate a starship, there are specialized JAGs in Starfleet, but every crew member is qualified in law. (Recall Picard mentioning his reputation as a litigator in "Devil's Due") As Starfleet grads are already canonically ridiculously, absurdly overqualified, adding in a legal qualification at the Federation Bar isn't that much of a stretch.
[And yes, as OP said, this is all just working overtime to find a way around the fact that the producers want the stars to do everything]