Theory of the phase transition in random unitary circuits with measurements