Classic Doctor Who: The Mind Robber
Episode 5
S1 E5:
The Doctor attempts to save his companions from being trapped within the fictional realm but instead finds himself imprisoned within the master brain itself.