Basically, the square root function is the inverse of the square function. However, we know that only bijections are invertible and $f:\mathbb{R}\to\mathbb{R}$ given by $f(x)=x^2$ is neither one-one nor onto, and thus, not a bijection.
Note that it being not a bijection, doesn't/can't have an inverse.
However, if we restrict the domain and the codomain of this function to the set of non-negative real numbers, $\mathbb{R_+}$, then $f:\mathbb{R_+}\to\mathbb{R_+}$ defined by $f(x)=x^2$ is a bijection and invertible. Its inverse is the famous square root function $f^{-1}:\mathbb{R_+}\to\mathbb{R_+}$.
Consequently, $\sqrt{x^2}=x$ only if $x\geq0.$