The crew of the Enterprise is sent to make contact with a superior race in the hopes of getting the kind of superior technology that would prevent folks from wanting to mess with Starfleet and the Federation. The superior race tells Kirk to get his ship out of their space because they don’t trust him. Shocking when you consider his history with superior beings and all situations in which he is told “No.”
So, like any dubious suitor who upon being told “No” repeats their request/demand only to be met with the silence of someone who’s trying to get on with things they actually want to be doing, Kirk ignores the request of the superior beings — which came hand-in-hand with a death threat by the way — and heads into the superior beings’ territory and is surreptitiously transported (along with McCoy, Spock, Scotty, & Chekov) by the superior beings to a movie set-esque representation of Tombstone, AZ on the day of the shootout at the OK Corral. Oh, and guess who’s been put on the losing side as punishment for going where they weren’t wanted.
The setting was determined by Kirk’s subconscious in a manner not unlike the Stay Puft marshmallow man of the first Ghostbusters film.
I’d write a poem for the episode, but the Inspiration Center in my brain just wants me to watch Ghostbusters; and, I like that plan, I’m excited to be a part of it.