Turnabout Intruder, the final episode of Star Trek TOS, drops a bombshell by revealing that Starfleet doesn't allow women to command starships; it's a tough one to swallow, given how progressive Starfleet is in most other respects.
Still, it's this astonishing fact that provides the basis for this enjoyable body swap tale in which Dr. Janice Lester, a nutty ex-flame of Kirk's, steals Jim's body (using an ancient alien machine) so that she can experience the power of being captain of the Enterprise. Meanwhile, Kirk finds himself trapped in Janice's body, but the way the story pans out, he doesn't even get an opportunity to enjoy his predicament (knowing horndog Kirk, first port of call would be a shower).
With crazy Janice calling the shots as Kirk, and desperate to keep Kirk (in her body) quiet, William Shatner is given free rein to act wildly, and the result is very entertaining -- some of Shatner's most 'expressive' work. Eventually, Kirk (as Janice) is able to convince Spock that she is the captain, and that the person now in command is an imposter. However, trying to prove this leads the Vulcan to be accused of mutiny. A court martial hearing is adjourned, but Janice (in Kirk's body) loses control, causing other members of the crew to side with Spock.
The conclusion is fairly weak, the problem conveniently resolving itself when Kirk's body rejects Janice's 'life entity', but everything that precedes it makes for a surprisingly entertaining swan-song for the iconic show.