This is a common misconception about the function $\sqrt{\cdot}\,:[0,\infty)\to\Bbb R$ as the "inverse" of $f(x)=x^2$.
In general, a function can have an inverse only when it is injective but $f(x)=x^2$ is not injective (e.g. $f(2)=f(-2) = 4$ ), so strictly speaking its inverse doesn't exist.
However, we can restrict its domain to $[0,\infty)$ and the function $f\lvert_{[0,\infty)}$ would be injective there, hence we can define $$\sqrt{x}:=f\lvert_{[0,\infty)}^{-1}.$$ The function $\sqrt{x}$ thus takes only one positive value for each input $x\ge 0$ (e.g. $\sqrt{4}=2$) even though there are two numbers such that $x^2=4$.
Remark: There are some cases where $\sqrt{\cdot}$ is defined to be multivalued, e.g. in complex analysis. However, $\sqrt{\cdot}$ wouldn't be a "function" in that case. Note also that we could very well define
$$\sqrt{x}:=f\lvert_{(-\infty,0]}^{-1}$$
and we'd have $\sqrt{4} = -2$ according to this definition. This is not popular for obvious reasons.