Continuously monitoring the environment of a quantum many-body system reduces the entropy of (purifies) the reduced density matrix of the system, conditional on the outcomes of the measurements. We show that, for mixed initial states, a balanced competition between measurements and entangling interactions within the system can result in a dynamical purification phase transition between (i) a phase that locally purifies at a constant system-size-independent rate and (ii) a "mixed" phase where the purification time diverges exponentially in the system size. The residual entropy density in the mixed phase implies the existence of a quantum error-protected subspace, where quantum information is reliably encoded against the future nonunitary evolution of the system. We show that these codes are of potential relevance to fault-tolerant quantum computation as they are often highly degenerate and satisfy optimal trade-offs between encoded information densities and error thresholds. In spatially local models in 1 þ 1 dimensions, this phase transition for mixed initial states occurs concurrently with a recently identified class of entanglement phase transitions for pure initial states. The purification transition studied here also generalizes to systems with long-range interactions, where conventional notions of entanglement transitions have to be reformulated. We numerically explore this transition for monitored random quantum circuits in 1 þ 1 dimensions and all-to-all models. Unlike in pure initial states, the mutual information of an initially completely mixed state in 1 þ 1 dimensions grows sublinearly in time due to the formation of the error-protected subspace. Purification dynamics is likely a more robust probe of the transition in experiments, where imperfections generically reduce entanglement and drive the system towards mixed states. We describe the motivations for studying this novel class of nonequilibrium quantum dynamics in the context of advanced quantum computing platforms and fault-tolerant quantum computation.