The Squire of Gothos (Star Trek)

On stardate 2124.5, the Federation starship USS Enterprise, under the command of Captain James T. Kirk, is on an 8-day supply mission to Colony Beta VI. Along the journey, the ship encounters a rogue planet in a "star desert" and described as being "in some sort of light warp" (preventing it from being detected sooner by the Enterprise).
Without the time to really stop and investigate it, Kirk orders the planet to be recorded for a future exploration mission and to continue with their original heading. When Lt. Sulu attempts to enter a course around the planet, he suddenly vanishes from the bridge. Kirk also vanishes moments later.
First Officer Spock believes that the two must have been taken to the mysterious planet below even though sensor readings indicate the planet's atmosphere is lethal to most forms of life. The Enterprise then receives a strange message on a viewscreen in blackletter writing, "Greetings and Felicitations!", after the Enterprise responds, a follow up message is sent "Hip hip hoorah. Tallyho!" Spock orders Chief Medical Officer Dr. McCoy, along with Lt. DeSalle and geophysicist Karl Jager, to form a landing party and conduct a search.
The landing party beams down and finds the area to be a lush and breathable environment, contradicting Jager's original scans that the world was barren and couldn't support life. They also come across what appears to be a medieval castle constructed in the middle of nowhere. They find Captain Kirk and Lt. Sulu, along with a brash and impetuous being who identifies himself as "General Trelane, Retired". McCoy's medical tricorder does not get any readings from Trelane and according to the scanner nothing is there. Trelane invites everyone to stay as his guests on his world he calls Gothos and discuss his favorite subject: the military history of Earth.
Spock, meanwhile, manages to locate the landing party in a minute zone of breathable atmosphere, and beams everyone, except Trelane, back to the ship by locking onto every detectable lifeform in the area. Unwilling to let his guests leave, Trelane makes an appearance on the Enterprise'​s bridge. He then brings the entire bridge crew back down to the planet. This time he includes Spock, Communications Officer Lt. Uhura and Yeoman Teresa Ross.
Kirk's patience begins to wear thin, especially when Trelane dances with Yeoman Ross and changes her standard red uniform into a flowing formal ball gown. Kirk and Spock both notice that their host never strays far from a particular wall mirror; they surmise that the mirror may be the source of his powers. To test this theory, Kirk provokes Trelane into a duel and during the fight he destroys the mirror and damages some strange machinery inside. It is discovered that Trelane uses this machine to manipulate matter for his amusement. The bridge crew manages to beam back to the Enterprise but, as the ship warps away, the planet Gothos keeps appearing in its path. Kirk finally orders the Enterprise into orbit and decides to beam down. As he enters the turbolift, he suddenly finds himself in a witness stand in a courtroom back on Gothos where the angry Trelane confronts him dressed in the white wig and robes of a British magistrate. Trelane tells Kirk he must face a trial for "treason", "conspiracy", and "fomenting insurrection". Silencing Kirk's protests, Trelane condemns Kirk to death by hanging. However, Kirk, to stall the execution, plays off of Trelane's childish whims by presenting him with a better idea.
In order to have his ship released, Kirk offers himself as the prey for a royal hunt. Trelane gleefully accepts and the hunt begins. Just as Trelane is about to kill Kirk, two energy beings appear and put a stop to his fun. It is revealed that Trelane is the "child" of the two beings. After apologizing to Kirk for their child's misbehavior, the beings disappear along with the whining Trelane, and Kirk is allowed to return to the ship.