Both proofs so far are for finite groups. However, the problem (with the complete assumptions) holds for not-necessarily-finite groups, provided that the group have no element of order $3$.
Here is a proof:
From $(ab)^3 = a^3b^3$, we immediately conclude that $(ba)^2 = a^2b^2$ by cancellation. We also conclude that cubes commute with squares, since $b^2a^2=(ab)^2 = (ab)^3(ab)^{-1}= a^3b^3b^{-1}a^{-1} = a^3b^2a^{-1}$, hence $b^2a^3=a^3b^2$.
Now, consider the cube of a commutator,
$$\begin{align*}
[a,b]^3 &= (a^{-1}b^{-1}ab)^3\\
&= a^{-3}b^{-3}a^3b^3\\
&= a^{-3}b^{-3}b^2a^3b\\
&= a^{-3}b^{-1}a^3b\\
&= [a^3,b].
\end{align*}$$
In particular, for any square we have $[a,x^2]^3 = [a^3,x^2]=1$, because cubes commute with squares. But since $G$ has no elements of order $3$, we conclude that $[a,x^2]=1$. Thus, we conclude that every square in $G$ is actually central.
But that means that $(ab)^2 = b^2a^2 = a^2b^2$ for all $a,b\in G$. And this condition is well known to imply that the group is abelian: $abab=aabb$ yields $ba=ab$.
In particular, this holds for a finite group whose order is not divisible by $3$.