The difference really lies in whether the function you're applying is injective. Essentially, a function $f:A\to B$ is called injective if $f(x)=f(y)$ implies that $x=y$ for all $x,y\in A$, i.e. each output only has one corresponding input. Now, the function $f:\mathbb R\to\mathbb R, x\mapsto x^2$ is not injective, because $(-a)^2=a^2$ but $a\neq -a$ for every nonzero real $a$. Therefore, when we have $a^2=b^2$, we cannot conclude that $a=b$, but we can only say that either $a=b$ or $a=-b$. We have introduced an "extraneous solution". But notice that this is only true because we allow all real--positive and negative--values of $a,b$. In particular, the function $g:\mathbb R_{\geq 0}\to\mathbb R,x\mapsto x^2$ is injective, so if we know that $a,b\geq0$ and $a^2=b^2$, then we do in fact know that $a=b$. No extraneous solution is introduced. In other words, the difference lies in that in the first case, we allowed all real values; but in the second case, we restricted to nonnegative real numbers.
Let's look at your example. In the first case, from $x^2=9$ we tried to conclude $x=3$ or $x=-3$. The solution $x=-3$ came from the fact that we did not know $x$ was positive from the equation. But in the second case, from $x=9$ it is in fact true that $\sqrt x$ can only be $3$, because we are restricting to positive values (recall square roots of real numbers are nonnegative). No extraneous solution introduced.