In every Lie group $G$ the function $x \mapsto x^2$ is a local diffeomorphism in a neighbourhood of the identiy.
(This is because its differential is: $v \mapsto 2v$ when considered as a map from $T_eG$ to itself).
In some Lie groups it is a global diffeomorphism, for instance in $\mathbb{R}^n$.
I would like to find more examples for Lie groups where the square is a global diffeomorphism. Are there any non-abelian groups where this holds?
Suppose so. I'm going to call the inverse $s$ for square root.
The exponential map of such a Lie group is automatically injective. For if $e(a)=e(b)$, then $s^k(e(a))=s^k(e(b))$; because we know square roots are unique in $G$, we know that $s^k(e(a)) = e(a/2^k)$. For large enough $k$, because the exponential map is a diffeomorphism near zero, we duduce $a/2^k=b/2^k$, hence $a=b$.
Now we may invoke the Dixmier-Saito classification of Lie groups with injective exponential to verify that the exponential is actually a diffeomorphism. Then define $s(g) = e(e^{-1}(g)/2)$. Because $e$ is a diffeomorphism, this is a well-defined smooth map, which you may check is the inverse of the squaring map.
Hence $x \mapsto x^2$ is equivalent to the exponential map being injective, which is equivalent to all the properties in the linked classification; in particular
One particular nontrivial example is the Heisenberg group. Note that this does not include all simply connected nilpotent Lie groups, because $\mathfrak e$ itself is nilpotent! So the universal cover of the group of oriented affine transformations of the plane is nilpotent but $x \mapsto x^2$ is not a diffeomorphism.