The Recruit: This is a prison?
The Imprisoned One: Can you think of a better prison than one without walls? What does your species use? Cages, I suppose.
Not all prisons are as simple as spartan cells, bad food, brutal guards and a crushing sense of confinement; some go the extra mile by warping your perception of reality and caging your consciousness as well. Here, the bodies of the inmates are kept in storage (if they're lucky) while their minds live out their sentence in a virtual reality scenario, or a Mental World, or perhaps something more magical.
Whatever the format and whatever the reason this system was adopted, you've committed a serious offence and the state has condemned you to a long stay inside your own head.
Life inside the prison varies: maybe it's a seductive Gilded Cage designed to reward good behavior; maybe it's a virtual hell where the residents are made to suffer for every minute of their simulated existence; or it could be so much like reality that it's impossible to tell the difference. Maybe the experience is the same in every cell, or maybe the punishment truly fits the crime. Maybe the prisoners will be released at some point in the future... or maybe they're jailed for the rest of their natural lives. It may even involve some kind of Artificial Afterlife if you're really unlucky. In extreme cases, Brain Uploading may be involved.
If the prisoner's being held for their knowledge, there may be a Virtual Reality Interrogation in play at some point. Depending on how much the inmates know of their prison, there may be a Journey to the Center of the Mind in order to break out, or even a Battle in the Center of the Mind against virtual guards. Escape, if at all possible, may require some sort of epiphany about their environment.
The key thing here is that the mental world has to be an officially-mandated punishment for it to qualify as this trope: it's not enough for a villain to trap the hero in a Lotus-Eater Machine or a Black Bug Room For the Evulz; it has to be either a punishment or an attempt to force reformation. In turn, the prison and/or punishment has to have been made legal - sometimes to the extent of an official trial and sentencing, sometimes just through the mandate of an absolute ruler or all-powerful police force... or, if you're dealing with an overtly supernatural setting, even a god.
In other words, if the use of a Mind Prison is a crime in this society, it doesn't count.
- Appears very early in The Sandman. Having been imprisoned on Earth by Roderick Burgess and his son Alex for seventy years, Dream of the Endless is not in a forgiving mood when he finally escapes. With Roderick long dead, Morpheus sentences Alex to an eternity of waking nightmares: comatose in the real world, his mind is trapped in a Russian doll of dreams in which he's always just waking up from his latest nightmare, only to find himself in another one.
- Darkdrive features such a prison being managed by an evil Mega-Corp, as it disposes of people by putting them in cryostasis and projecting their minds into the virtual world. The main character goes inside the mental prison to track down a specific person.
- In Minority Report, criminals captured by the Precrime division are sentenced to Cryo-Prison, during which their minds are trapped in an inescapable dream state. According to the jailer, "your life flashes before your eyes" and "all your dreams come true."
- In the Australian sci-fi movie Other Life, a form of biological VR is invented and soon proposed as a Year Inside, Hour Outside alternative to prison. Though the creator protests this idea, she soon finds herself on the receiving end of this when one of her VR programs accidentally kills a coworker, resulting in her being sentenced to a year of solitary confinement in the OtherLife simulation as punishment for unlicensed human testing and manslaughter. For good measure, it's also made clear that this is the more lenient option compared to a trial and a longer jail term. Except it turns out that the coworker survived, and the sentence may not be as legit as it first appears.
- In The Fractured Atlas - Five Fragments by John Connolly, anyone who makes the mistake of messing with the eponymous book is condemned to spend eternity in the company of the Not-God. Here, the main character of the final story has his mouth and eyes sewn shut, while his mind is trapped in an endless nightmare of his time in World War I. Just to drive home the awful cosmic legality of it all, his sentence is presided over by a lawyer who doubles as his jailer.
- Variation: in Ready Player One, IOI employs wage slaves and indentured debtors in the virtual reality world of OASIS, holding rooms full of prisoners using VR helmets to earn in-game currency and unlock prizes - all of which are kept by the company. As it happens, this is actually a practice directly inspired by the modern use of prison telemarketers.
- Red Dwarf: Last Human introduces us to the Penal Colony of Cyberia, where individuals convicted of crimes against the GELF state spend their sentences in virtual reality scenarios tailor-made to inflict the maximum amount of discomfort, boredom, frustration and all-around misery. It turns out that the GELF state's justice system is a sham designed to convict as many people as possible in order to acquire "volunteers" for an emergency terraforming project. Since the alternative to the project is another stint in virtual hell, most prisoners agree to the terms immediately as soon as they're offered.
- In Lies of the Beholder there is the Walters and Ostman Detention Enterprises, a company that aims to create such prison and tout such benefits as it being much cheaper and making inmates' rehabilitation easier, as well as seeing if an inmate is likely to get back to life of crime — all this by making them live through various scenarios. The only problem is, their solution is still not really viable for longer periods, as human minds reject such manipulation.
- Combined with Virtual Reality Interrogation in Black Mirror. Over the course of the episode "White Christmas," a suspected murderer's mind is copied into a virtual world so the police can subtly coerce him into confessing. Eventually, they get the confession they wanted... but instead of just deleting the copy, they decide to leave him in the virtual world as "a proper sentence," with the time settings cranked up to a thousand years a minute. As a result, the poor bastard is left alone in a room furnished with unwanted reminders of his crime, with "I Wish It Would Be Christmas Everyday" playing at full volume in the background.
- In Dollhouse, house employees who abuse the Actives or otherwise make trouble for the house get sent to The Attic, where they are put into stasis and subjected to nightmares while their brains are used to provide processing power for the house's network.
- In the Doctor Who spinoff series K9, virtual reality detention facilities are quite common, serving as repositories for criminals, political dissidents or embarrassing mistakes made by the Department. Inside their simulations, prisoners are housed in cells composed of "nothing but white," with no details to distract the mind; as a result, long-term incarceration inside virtual environments like these is nothing short of hellish.
- The I-Land: In episode 3, it's revealed that the island is actually a shared simulation developed by the American prison system 20 Minutes into the Future in order to rehabilitate criminals. It's only in its pilot phase, so the programmers are still ironing out the system's faults. It also operates on a non-fixed Year Outside, Hour Inside differential.
- Hell, as depicted in Lucifer. The damned souls spend eternity in an illusion, receiving the punishment they believe they deserve. They're actually free to leave at any time, but they never do.
- The Outer Limits (1995): In the episode "The Sentence", a scientist named Dr. Jack Henson creates one of these, which, like the Star Trek: Deep Space Nine example below, works on a Year Inside, Hour Outside basis. Unfortunately, when it's tested on a man named Cory Izacks who - unknown to all - was wrongly convicted, it malfunctions and starts killing him instead. Jack plugs himself into the machine in an attempt to rescue Izacks, but fails and goes to jail for second-degree murder. After decades spent in a Hellhole Prison, he awakens to discover that he was just trapped in the simulation: in reality, he managed to save Izacks' life; unfortunately, Jack is left with severe PTSD and convinced his machine must be destroyed. Worse still, the demonstration has managed to impress the observing US Senator Meade, and he plans to have the machine approved for use on the general population.
- Hell also operates this way in Preacher. Reimagined as a massive prison complex complete with guards and wardens, the inmates of Hell spend their time in bare concrete cells, being constantly forced to relive the worst moments of their lives through mechanical projectors. Occasionally, the projectors break down and the inmates are given a brief respite in a particularly miserable breakroom while the machines are fixed. Breaking the rules here - ie: by being kind or helpful in any way - will result in the offender being sent to The Hole, in which the aforementioned worst moments are made even worse through virtual reality.
- Appears in the Star Trek: Deep Space Nine episode "Hard Time." Here, an alien culture has done away with the hassle of maintaining a real prison system by simply implanting criminals with a virtual prison experience. The punishment lasts only a few hours, but inside their minds, the prisoners can spend entire lifetimes in hellish prison conditions with minimal food and constant paranoia. As O'Brien discovers, the aftermath of such sentences can be nothing short of devastating.
- The Twilight Zone (2002) episode "The Pool Boy" is about a man who experiences being murdered by an unknown assailant every day before he wakes up that morning to start the cycle anew. At the end it's shown that he's a murderer who's been sentenced to a mind prison, and the man who kills him repeatedly is a projection of his victim tormenting him.
- Crops up in the The End of the World: Revolt Of The Machines. In the post-apocalyptic segment of the scenario "Logical Conclusions," a group of fanatically-patriotic cyborgs have taken over America, nuked the world into an irradiated hellhole, and are now incorporating surviving American citizens into communal virtual reality pods a la The Matrix. The goal here is apparently rehabilitation: most citizens are left in a pleasant-but-confusing haze of patriotic propaganda to make them more pliable, while those judged "deserving" are given an idealized simulation of the 1950s to live out their days in.
- Knights of the Old Republic provides the Trope Namer. At one point, you're given a mysterious box to deliver and told not to open it at any cost. Actually doing so plunges you into a Blank White Void in which an ancient Rakatan has been imprisoned - with no entertainment and only a bed for furniture. Apparently, Mind Prisons such as these were popular back in the days of the Rakatan Infinite Empire, and considered far more effective than any physical prison. Indeed, this piece of Force-based technology worked so well that the inmate has outlived the Empire that sentenced him; by now, he desperately wants out... and since his original body died eons ago, he needs yours.
- The majority of Saints Row IV takes place in one of these, as it's Emperor Zinyak's policy to imprison criminals and enemy VIPs in simulations based on their worst nightmares, while their bodies remain stuck in pods aboard his ship: the Boss is trapped in a 1950s sitcom town where unlawful acts are impossible until the brainwashing breaks down; Matt Miller finds himself imprisoned in an old fashioned text adventure in which he is at the mercy of Killbane; Shaundi is forced to relive the death of Johnny Gat; Pierce is constantly being attacked by an army of living Saints Flow merchandise; Benjamin King finds himself in a recreation of his past where his old gang, the Vice Kings, turn on him; finally, Asha is pitted against a seemingly impossible mission to stop an evil version of the Boss. In a surprise twist, Johnny Gat turns out to still be alive in the simulation, and is trapped in a side-scrolling fighting game in which he has to witness the death of Aisha again.
- A decidedly eldritch version of this appears in The Secret World, where it's eventually revealed that the appropriately-named Dreamers have been imprisoned in a state of unending sleep through the power of the Gaia Engines; essentially giant musical boxes, they ensure that the prisoners can never threaten existence, instead forcing them to live out their fantasies of escape in their dreams. For good measure, the Gaia Engines also harness the power of the Dreamers to keep reality on track, and it's suggested that their imprisonment by the Host might be the only reason our universe exists in the first place. Trouble is, the Engines have begun to malfunction over the eons, allowing the dreams of these Lovecraftian baddies to leak out in physical form - to the point that you can actually visit one of their dreams of the world as they'd want it to be.
- Season two of Rick and Morty ends with Rick being sent to prison for various crimes against the Federation or — as Rick puts it — for "everything." In the first episode of the next season, it's revealed that most of Rick's time in prison has been spent in Virtual Reality Interrogation so the Federation can learn how his portal gun works. From the sounds of things, most of it involved a detailed scenario in which he escapes from prison and returns to Earth; however, Rick figures out what's going on very quickly. For good measure, this is also being used as a form of execution: once they think they've gotten everything from him, the agent in charge is planning to leave Rick in there until the Mind Probe melts his brain.