An example of a non-abelian group $G$ where, for all $a,b\in G$, the equality $(ab)^{n}=a^{n}b^{n}$ holds for two consecutive integers $n$
$D_4$ should work with $r^4=1$ commuting with $s^3=s$ and $r^3$ commuting with $s^2=1$
Consider the symmetric group of order $3$ , $S_3$, and then the result holds for $i=0$ and $i=1$ (equivalently, for $i=6$ and $i=7$). Note that the result does not hold for $i = 2$.
In fact there is another theorem which states that a group is abelian if the result holds, for only $i=2$.
A trivial example is $a^0b^0=(ab)^0$ and $a^1b^1=(ab)^1$, which hold for $\forall a,b\in G$ with $G$ being any non-Abelian groups.
A non-trivial example is dihedral groups $D_4$ of order $8$: It will be obvious that $a^4 b^4=(ab)^4$ and $a^{5} b^{5}=(ab)^{5}$ hold, once you prove $\forall g\in D_n, g^n=e$.
In fact, Lagrange's theorem says that, for any finite group $G$, there exists $n\in\{\text{divisors of }|G|\}$ such that $g^n=e$ for all $g\in G$. So $g^{|G|}=e$ holds for any finite groups.