Suppose π is a homomorphism, and fix x, y ∈ G. Then (xy)2 = x2 y2, or xyxy = xxyy. Left cancellation of x on both sides of the equation yields yxy = xyy. Right cancellation of y on both sides results in yx = xy. Since x and y were arbitrary, G is abelian,
Conversely, suppose G is abelian. Since xy = yx for all x, y ∈ G, we have
(xy)2 = x(yx)y = x(xy)y = x^2 y^2
showing that π is a homomorphism.