why does the water line flatten out after 0 celsius

What do you mean by "the water line" and "flatten out" ?

If you mean why does the temperature remain 0 C while ice is melting or freezing, there is a certain unique temperature when two phases can coexist, for pure compounds. This fact can be predicted with statistical mechanics, and was first explained by Josiah Willard Gibbs.

It is called the Gibbs Phase Rule.