Solution to Abstract Algebra by Dummit & Foote 3rd edition Chapter 1.6 Exercise 1.6.18
Let $G$ be a group. Show that the map $\varphi : G \rightarrow G$ given by $g \mapsto g^2$ is a homomorphism if and only if $G$ is abelian.
Solution:
($\Leftarrow$) Suppose $G$ is abelian. Then $$\varphi(ab) = abab = a^2 b^2 = \varphi(a) \varphi(b),$$ so that $\varphi$ is a homomorphism.
($\Rightarrow$) Suppose $\varphi$ is a homomorphism. Then we have $$abab = \varphi(ab) = \varphi(a) \varphi(b) = aabb,$$ so that $abab = aabb$. Left multiplying by $a^{-1}$ and right multiplying by $b^{-1}$, we see that $ab = ba$. Thus $G$ is abelian.