In MASH, Hawkeye and Trapper and BJ Honeycutt aren't going to be allowed to break the rules and piss off higher ups if they were following a true military structure they'd be in prison no matter how talented they are. Likewise, Klinger wouldn't be allowed to walk around in a dress for five years, they'd drop him in a psychiatric ward and forget about him.
In TNG, Riker wouldn't be allowed to turn down commands time and again no matter how badly he wanted to stay on the Enterprise
. They also wouldn't allow a child on the bridge performing duties of more experienced, trained officers.
Any entertainment would fail miserably if we put in under the microscope we put Star Trek under.