I can't seem to understand this even though it might be utterly simple for some people. For me, saying $|x|=\sqrt{x^2}$ is a bit weird since $\sqrt{x^2}$ doesn't force positivity as there are always two possible square roots of a number, $\sqrt{x}=+\sqrt x, -\sqrt{x}$. Then why is it still used everywhere? Is there another way of interpreting this?
I think $|x|=(\sqrt x)^2$ does the job much better.
One needs to distinguish two concepts.
A square root of $a$ is any number whose square is $a$. This definition is valid in any number system, not necessarily restricted to non-negative real numbers.
Also, this definition never tells that such number is unique, and in fact, there are exactly two square roots for a given non-zero number either in $\mathbb{R}$ (real numbers) or in $\mathbb{C}$ (complex numbers).
The square root of $a$ for $a \geq 0$ is defined as the unique non-negative square root of $a$. This square root is denoted by $\sqrt{a}$.
Assuming OP has knowledge on complex numbers, the principal square root of a complex number $z$ can be defined as the square root $w$ of $z$ with $\arg(w) \in (-\pi/2, \pi/2]$. This $w$ is denoted as $\sqrt{z}$. It is easy to check that this definition of $\sqrt{z}$ extends the previous one when $z \in [0, \infty)$.
If $x$ is a square root of $a$, then by definition we necessarily have $x^2 = a$. In particular, $(\sqrt{a})^2 = a$ always holds by definition.
Finally, for each $x \in \mathbb{R}$,
Square roots of $x^2$ are $x$ and $-x$.
$\sqrt{x^2}$ is the unique non-negative square root of $x^2$.
So if $x \geq 0$, then $x$ is non-negative and $\sqrt{x^2} = x$. If $x \leq 0$, then $-x$ is non-negative and $\sqrt{x^2} = -x$. Combining both cases, we obtain $\sqrt{x^2} = |x|$.