The Portreeve of Castrovalva is revealed to be the Master in disguise who, as the Doctor discovers, created Castrovalva himself to trap his newly regenerated arch-enemy.
The Doctor discovers Castrovalva is a cursive occlusion, an impossible yet manifested Escheresque environment, with all pathways, no matter which direction one goes, leading back to the same point. It is a trap laid by the Master with no apparent way out.—statmanjeff