In the episode, Commander Riker switches between mental realities: performing in one of Dr. Crusher's plays, preparing for an undercover away mission and being an inmate in an alien asylum for the criminally insane, charged with murder.
Prior to taking a covert mission, Riker is rehearsing for a theater play "Frame of Mind" for the Enterprise. The play involves Riker's character confined to a mental asylum, and involves a soliloquy regarding the nature of being sane. During practice for the mission, he is accidentally injured by Lt. Worf on the side of his head, and while Dr. Crusher heals the wound, Riker still experiences some pain there. Riker performs the play for the crew, and receives a standing ovation, except for one officer in the center of the crowd who frowns at the performance. Riker takes a bow, but when he straightens, he finds the audience gone, himself trapped in a cell similar to the set for the play. An alien humanoid doctor iterates "I see we still have much work to do", a line from the play, before locking Riker in the cell.
Later, Riker is taken to the asylum cafeteria, reminded that he is there because he killed a man. Riker becomes agitated by this news, and the doctors inject him with more drugs, knocking him out. Riker finds himself back on the Enterprise, but this is a figment of his imagination: after seeing one of the alien doctors several times, he flees to his quarters only to find himself back in the asylum cell. The doctors, attempting to quench Riker's hallucinations about the Enterprise, use a procedure that produces holographic projections of the Enterprise which Riker is forced to reject to gain the confidence of his doctor.
The next day while in the cafeteria, Riker refuses to talk with what he believes is a hallucination of Dr. Crusher, warning him that they are planning on rescuing him. That night, Worf and Data appear and free Riker, overwhelming the guards and returning him to the Enterprise. Riker, still defiant that the Enterprise is not real, complains of pain in his head; the same wound from before. Dr. Crusher cures it but it returns immediately, leading Riker to believe that this is another hallucination. He proves this to himself by firing a phaser at himself; the scene shatters, and he finds himself back in the asylum cell under the watchful eye of the doctors. He realizes he is still holding a phaser, though the doctors claim that it is a knife. When the head pain strikes again, Riker dismisses this scene as reality, and sets the phaser to overload which would take half the facility with it. When it goes off, he finds himself on the stage of his play, the crowd giving a standing ovation. Riker refuses to accept this as real, and pounds on the wall of the set, shattering that reality.
Riker recovers consciousness to find himself on an operating table, a device inserted into his head where he has been experiencing pain. Riker frees himself from the table, renders an alien doctor unconscious, and recovers his communication badge on a nearby table, requesting an immediate beam-out. Riker shortly finds himself back safely aboard the Enterprise. As Dr. Crusher tends to his wounds, he learns that he was captured on the covert mission he was on, and the aliens were scanning his brain to discover strategic information about the Federation. The strange experiences he saw were a result of his own subconscious fighting against the probe. After recovering, Riker returns to the set of the play one last time to dismantle it.