Star Trek The Original Series S01 E17 – The Squire of Gothos
The Enterprise discovers a rogue planet drifting through space, inhabited by an eccentric being named Trelane who uses his apparently unlimited power over matter and form to manipulate the crew.