TITLE: Prove that $G$ is abelian iff $\varphi(g) = g^2$ is a homomorphism
QUESTION [6 upvotes]: I'm working on the following problem:

Let $G$ be a group. Prove that $G$ is abelian if and only if
  $\varphi(g) = g^2$ is a homomorphism.

My solution: First assume that $G$ is an abelian group and let $g, h \in G$. Observe that $\varphi(gh) = (gh)^2 = (gh)(gh) = g^2h^2 = \varphi(g)\varphi(h)$. Thus, $\varphi$ is a homomorphism.
I'm having trouble completing the proof in the reverse direction. Assume that $\varphi$ is a homomorphism. We then know that $\varphi(gh) = \varphi(g)\varphi(h)$ and $\varphi(hg) = \varphi(h)\varphi(g)$. However, I don't see a way to use this to show that $gh = hg$.
Could anyone lend a helping hand?

REPLY [2 votes]: Assume $\varphi(g) = g^2$ is a homomorphism and $G$ is non-abelian; we will show a contradiction.
Since $G$ is non-abelian, we can choose $g, h \in G : gh \neq hg$. 
Then since $\varphi$ is a homomorphism,
$$ \varphi(gh) = \varphi(g) \varphi(h) = gghh $$
So $$ ghgh = gghh $$
Left multiply be $g^{-1}$ and right multiply by $h^{-1}$:
$$ gh = hg $$
which contradicts our choice of $(g, h)$.  Thus it is impossible to choose $g$ and $h$ that don't commute, thus $G$ must be Abelian.