Starfleet has a JAG corps that provides legal council to its Crewmen and Officers. It has been mentioned in several series (TOS "Court Martial", TNG "The Measure of a Man", DS9 "Doctor Bashir, I presume").
Whether and which Enterprises had a JAG officer on board has not been mentioned.
My assumption is that every Command Officer has received training in Starfleet and Federation Law.
There's probably a basic survey course at Starfleet Academy in Federation law and Starfleet regulations. Similar to the situation for physicians (McCoy may not have attended Starfleet Academy, since he did not know what a "dunsel" was in the Star Trek: The Original Series episode "The Ultimate Computer") Starfleet Academy may maintain its own law school, as does today's U.S. military for graduate legal studies, therefore officer candidates probably attend an outside law school in addition to their studies at Starfleet Academy (although it is certainly possible that there is a law faculty at Starfleet Academy administering a full legal studies curriculum).
In the Star Trek: The Next Generation episode "Measure of a Man", it seems from dialogue that it is unusual that legal specialist officers were not available, and Captain Louvois mentions to Picard that line officers may serve as counsel in such cases, which also suggests that JAG officers do not serve in a line capacity aboard ship, although officers with significant legal experience may serve in other, line, capacities. We never saw a true trial depicted in the events of the "Measure of a Man" subject to rules of civil or criminal procedure and rules of evidence, as today's courtroom procedures are subject; and, an understanding of how these work are essential to the conduct of courtroom law, under both military and civilian law (for a good depiction of military procedural law references, see the movie A Few Good Men).
Also, there was another episode where Riker was accused under planetary law (it was never specified whether the planet was a member of the United Federation of Planets). It seemed like a quasi-trial, or a long, drawn-out, probable-cause hearing (known today in U.S. civilian law as a "Gerstein hearing"). Usually, probable-cause hearings simply involve a judge reviewing a PCA (probable-cause affidavit), which, if accepted as being in existence by the judge, is followed by a charging information (usually for misdemeanors) or an indictment (in the case of felonies), which may be issued by a prosecutor, or on the findings of a grand jury (in use in U.S. federal law, and in many U.S. States) which specify particulars of the charged offense and enumerate which statutes are alleged to have been violated.
The existence of a Federation judiciary has been mentioned (thus there are three distinct and structured branches of UFP government, as there is in the U.S.), as have been the existence of "Starfleet regulations", probably similar to today's Uniform Code of Military Justice, which also would mean that Starfleet probably has its own court system under the Federation judiciary for the adjudication of legal matters concerning Starfleet personnel. ProfessorTrek 11:01, July 29, 2011 (UTC)