I was trying a problem and was getting the wrong answer and when I saw the solution on the internet I found this statement written in square brackets $\sqrt{x^2}$[note square is on $x$] is $|x|$. Till now I have learned that by laws of exponents we can multiply the powers and obtain $\sqrt{x}^2$ as $x$. But this seems confusing to me. Please clear this doubt.
And does this apply to $\left({\sqrt x}\right)^2$[note square is on radical] i.e. is $\left({\sqrt x}\right)^2 = |x|$?
The square root of $x$ is a non-negative number $y$ such that $y^2=x$. Thus the square root of $x^2$ is a non-negative number $y$ such that $y^2=x^2$. To make sure the square root of $x^2$ is non-negative then you take $y=\lvert x\rvert$.
In the second part, writing $(\sqrt{x})^2$ means that $x \geq 0$, so $\lvert x\rvert = x$, and you can safely say $(\sqrt{x})^2 = x$.