To show that group G is abelian if $(ab)^3 = a^3 b^3$ and the order of $G$ is not divisible by 3 
Let $G$ be a finite group whose order is not divisible by $3$.
  suppose $(ab)^3 = a^3 b^3$ for all $a,b \in G$. Prove that $G$ must be abelian.

Let$ $G be a finite group of order $n$. As $n$ is not divisible by $3$ ,$3$ does not divide $n$ thus $n$ should be relatively prime to $n$. that is gcd of an $n$ should be $1$.
  $n =  1 ,2 ,4 ,5 ,7 ,8 ,10 ,11, 13 ,14 ,17,...$
 further I know that all groups upto order $5$ are abelian and every group of prime order is cyclic. when it remains to prove the numbers which are greater than $5$ and not prime are abelian.
Am I going the right way?
 please suggest me the proper way to prove this.

I have followed the similar method as previous answer with a few changes (without defining the $f$, thought it would be easier:) )
As $(ab)^3=a^3b^3$ for all $a,b\in G$
we have \begin{align*} ababab&=aaabbb\\
\Rightarrow baba&=aabb\\
\Rightarrow (ba)^2&=a^2b^2 \end{align*}
Consider,
\begin{align*}(ab)^4&=((ab)^2)^2\\
&=(b^2a^2)^2\\
&=a^4b^4
\\
&=aaaabbbb\end{align*}
Also
\begin{align*}
(ab)^4&=abababab\\
&=a(ba)^3b
\end{align*}
Therefore, we get
\begin{align}aaaabbbb&=a(ba)^3b\\
\Rightarrow (ba)^3&=(ab)^3\\
\Rightarrow (ab)^{-3}(ba)^3&=e
\end{align}
Where $e$ is identity in $G$
$$\Rightarrow [(ab)^{-1}(ba)]^3=e$$
Now for $x=(ab)^{-1}(ba)$ ,$|x|$ divides $3$ by which $|x|$ can be $3$ or $1$.
Now $|x|$ can not be $3$ (as by Lagrange's theorem if $|x|$=3 then $3$ divides $|G|$ which is not true).
Thus,
\begin{align*}
|x|&=1\\
\Rightarrow x&=e\\
\Rightarrow (ab)^{-1}(ba)&=e
\end{align*}
Multiplying by $ab$ from left,
$$\Rightarrow ba=ab$$ for all $a,b\in G$.
Thus, $G$ is abelian.
