Reversible mode switching in Y-coupled terahertz lasers