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
- $G$ is solvable, simply connected, and $\mathfrak{g}$ does not admit $\mathfrak{e}$ as subalgebra of a quotient.
- $G$ is solvable, simply connected, and $\mathfrak{g}$ does not admit $\mathfrak{e}$ or $\tilde{\mathfrak{e}}$ as subalgebra
Here $\mathfrak{e}$ is the 3-dimensional Lie algebra with basis $(H,X,Y)$ and bracket $[H,X]=Y$, $[H,Y]=-X$, $[X,Y]=0$. It is isomorphic to the Lie algebra of the group of isometries of the plane. Its central extension $\tilde{\mathfrak{e}}$ is defined as the 4-dimensional Lie algebra defined by adding a central generator $Z$ and the additional nonzero bracket $[X,Y]=Z$.
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.