The Twelfth Doctor was sent there on a trumped up charge, due to stopping a missile attack. To his surprise, the Governor found that the Doctor continually tried escaping the Prison. Adding onto the strangeness was Clara constantly trying to visit; used to people trying and failing to visit because of the idiotic protocols, he attempted to send her away and relay messages she left. At the time, power outages had also begun, and the Doctor was the only one who could be blamed. However, to his surprise, the Doctor undermined his authority and began trying to make prison life better for the inmates, even making friends. Once a 7 minute blackout occurred, he decided to eject Level 7 (which held the children of those opposing HomeWorld) to save resources. However, at the time, the Prison had been rewired to turn against him and the staff by the corrupt government, to prevent anyone from leaving and to cover up their tracks.
The Doctor and Clara worked with him to discover that a hidden robot had been killing prisoners in an attempt to understand humanity; they destroyed it and had some tea. At that point, he began a journal, the very novel that had been read, as he pondered what to do with his life next. (PROSE: The Blood Cell)