Proof. Assume that for all g in G that g^2 = e holds. Let a,b \in G. Then since G is a group, we know that ab \in G. Further, we know that a^2 = e and that b^2 = e. Now take (ab)^2 = abab. Because (ab)^2 = e, we have that abab = e. Now, multiply b^{-1}a^{-1} on both sides on the right side of abab = e, then we get ab = b^{-1}a^{-1}. As a^2 = e, we have that a = a^{-1}. The same holds argument for b. So we get ab = b^{-1}a^{-1} = ba. Wrapping everything together, we can write the proof as
\begin{align*} (ab)^2 = e &\iff abab = e \\ &\iff ababb^{-1} = b^{-1} \\ &\iff aba = b^{-1} \\ &\iff abaa^{-1} = b^{-1}a^{-1} \\ &\iff ab = b^{-1}a^{-1} \\ &\iff ab = ba \quad \text{because } a = a^{-1} \text{ and } b = b^{-1}. \end{align*}