Problem: Let $G$ be a finite group whose order is not divisible by $3$. Suppose that $\left( ab \right) ^3 = a^3 b^3$ for all $a,b \in G$. Prove that $G$ is abelian.
Solution: Let the order of the group $G$ be $n$. According to the given hypothesis, $3$ does not divide $n$. Since, $3$ is a prime number, so we have
\[
\gcd(3,n) = 1.
\]
The above implies, there exists $x,y\in \mathbb{Z} $ such that
\begin{equation}\label{eq:01Mar2023-1}
3x+ny = 1 .
\end{equation}
Now note that for any $a,b\in G$,
\begin{align*}
ab & = (ab)^{3x+ny} \\
& = (ab)^{3x} (ab)^{ny}\\
& = \left( (ab)^3 \right)^x \left( (ab)^n \right)^y \\
& = \left( a^3 b^3 \right)^x e^y \quad \textcolor{magenta}{\boxed{\text{as $|G|=n$}}}\\
& = \left( a^3 b^3 \right)^x \\
& = a^3 \underbrace{\left( b^3 a^3 \right) \left( b^3 a^3 \right) \cdots \left( b^3 a^3 \right)}_{(x-1)-\text{times}} b^3 \\
& = a^3 \left( b^3 a^3 \right)^{x-1} b^3 \\
& = a^3 \left( ba \right)^{3x-3} b^3 \quad \textcolor{magenta}{\boxed{b^3 a^3 = (ba)^3}} \\
& = a^3 (ba)^{3x} (ba)^{-3} b^3 \\
& = a^3 (ba)^{3x} \cdot e \cdot (ba)^{-3} b^3 \\
& = a^3 (ba)^{3x} \cdot (ba)^{ny} \cdot (ba)^{-3} b^3 \\
& = a^3 (ba)^{3x+ny} ba^{-3} b^3 \\
& = a^3 (ba) (ba)^{-3} b^3 \quad \textcolor{magenta}{\boxed{\text{from \eqref{eq:01Mar2023-1}}}} \\
& = a^3 (ba) \left( a^{-3}b^{-3} \right) b^3 \\
& = a^3 b a^{-2}.
\end{align*}
Therefore, we got
\begin{align*}
& ab = a^3 b a^{-2} = a^3 b^3 b^{-2} a^{-2} \\
\implies & ab = (ab)^3 b^{-2}a^{-2} \\
\implies & (ab)^2 b^{-2} a^{-2} = e\\
\implies & (ab)^2 = a^2 b^2 \\
\implies & ab ab = a^2 b^2 \\
\implies & a^{-1}(ab ab)b^{-1} = a^{-1} \left( a^2 b^2 \right)b^{-1} \\
\implies & ba = ab.
\end{align*}
Hence, we proved that $G$ is abelian.
Second method (taken from
here).
Given that for any $a,b\in G$
\begin{align*}
(ab)^3 = a^3 b^3 & \implies (ab) (ab) (ab) = a^3 b^3
\\
& \implies a^{-1}ab(ab)ab b^{-1} = a^{-1}a^3b^3 b^{-1}
\\
& \implies baba = a^2 b^2
\\
& \implies (ba)^2 = a^2 b^2.
\end{align*}
Thus,
\begin{equation}\label{eq:01Mar2023-2}
(ba)^2 = a^2b^2 \qquad\forall~a,b\in G.
\end{equation}
Now we consider the commutator of $a,b$ which is $aba^{-1} b^{-1} $
\begin{align*}
\left( aba^{-1} b^{-1} \right) ^2 & = \left( a^{-1} b^{-1} \right) ^2 (ab)^2 \quad \textcolor{magenta}{\boxed{\text{from }\eqref{eq:01Mar2023-2}}}\\
& = b^{-2} a^{-2} b^2 a^2 \quad \textcolor{magenta}{\boxed{\text{from }\eqref{eq:01Mar2023-2}}}\\
& = b^{-2} \left( ba^{-1} \right) ^{-2} a^2 \\
& = b^{-2} ba^{-1} ba^{-1} a^2 \\
& = b^{-1} a^{-1} ba.
\end{align*}
Therefore,
\begin{equation}\label{eq:01Mar2023-3}
\left( aba^{-1} b^{-1} \right) ^2 = b^{-1} a^{-1} ba \qquad\forall~a,b\in G.
\end{equation}
Squaring \eqref{eq:01Mar2023-3}, we get
\begin{align*}
\left( aba^{-1} b^{-1} \right) ^4 & = \left( b^{-1} a^{-1} ba \right) ^2 \\
& = aba^{-1} b^{-1} \quad \textcolor{magenta}{\boxed{\text{from } \eqref{eq:01Mar2023-3}}} \\
\implies \left( aba^{-1} b^{-1} \right) ^3 & = e.
\end{align*}
Note that we have given that the order of the group is not divisible by $3$ and hence none of the element order will be $3$. Therefore,
\[
aba^{-1} b^{-1} = e \implies ab = ba.
\]
Hence, $G$ is abelian.