Thank you for pointing out why my second code was wrong! Yes, the solution was oscillating around u[2]=1, since the vector fields in the two sides of u[2]=1 are squeezing towards u[2]=1. Just like this picture:
In non-smooth nonlinear dynamics, this phenomenon is called the sliding mode. My question is whether the existing solvers can handle this sliding mode more accurately. For example, detect when the solution enters the sliding mode or when it exits, and the solution can just slide along the switch surface, without oscillating.