We had a thread about this recently. The point is that [tex]\sqrt{x^2}\neq x[/tex]. The square root of x is defined as the unique POSITIVE number who's square is x. Thus [tex]\sqrt{(-3)^2}[/tex] is the unique positive number who's square is [tex](-3)^2=9[/tex], obviously, this number is 3.
Thus, in general, we have that [tex]\sqrt{x^2}=|x|[/tex].
So, your first equation:
[tex](-3)^2=(\sqrt{9})^2[/tex]
is true, since [tex](-3)^2=9[/tex]and [tex]\sqrt{9}=3[/tex] and [tex]3^2=9[/tex]
But when taking the square root of both sides we get
[tex]\sqrt{(-3)^2}=\sqrt{(\sqrt{9})^2}[/tex]
which evaluates to [tex]3=\sqrt{9}[/tex], which is perfectly true!