I was writing this as a comment, but it's going to be extensive; I suspect most of the commenters might be interested, so here goes as a community wiki.
A group $G$ is said to be $n$-abelian if $(ab)^n = a^nb^n$ for every $a,b\in G$.
Alperin proved (The classification of $n$-abelian groups, Canad. J. Math. 21 (1969) 1238-1244, MR0248204 (40 #1458)) that the variety of $n$-abelian groups is the join of the variety of abelian groups, the variety of groups of exponent $n$, and the variety of groups of exponent dividing $n-1$ (so a group is $n$-abelian if and only if it is a quotient of a subgroup of a direct product of groups that are either abelian, of exponent $n$, or of exponent dividing $n-1$).
More recently, Primož Moravec (Schur multipliers and power endomorphisms of groups. J. Algebra 308 (2007), no. 1, 12–25. MR2290906 (2007j:20047)) proved that a finite $p$-group is $n$-abelian if and only if $n\in p^{e+r}\mathbb{Z}\cup(1+p^{e+r})\mathbb{Z}$, where $p^e$ is the exponent of $G/Z(G)$ and $r$ is an integer that can be computed, called the "exponential rank of $G$".
A closely related class of groups are the $n$-Bell and the $n$-Levi groups. A group is $n$-Bell if and only if $[x^n,y]=[x,y^n]$ for all $x,y\in G$, where $[a,b]$ is the commutator of $a$ and $b$. A group is $n$-Levi if $[x^n,y] = [x,y]^n$ for all $x,y\in G$. (Note that since $[a,b]=[b,a]^{-1}$, $n$-Levi implies $n$-Bell). A result I noted in passing some years ago was that if a group is $i$-, $i+1$-, and $i+2$-Levi for some integer $i$, then it is $n$-Levi for all $n$ (and hence nilpotent of class at most $2$), very similar to the problem at hand here. Also, $2$-Levi and $(-1)$-Levi imply $n$-Levi for all $n$, just like $(-1)$-abelian and $2$-abelian imply abelian (i.e., $n$-abelian for all $n$).
A nice paper on this subject is L-C Kappe's On $n$-Levi groups.
Arch. Math. (Basel) 47 (1986), no. 3, 198–210, MR 0861866 (88a:20048). For a group $G$, let
$$\begin{align*}
\mathcal{E}(G) &= \{n\mid (xy)^n = x^ny^n\text{ for all }x,y\in G\}\\
\mathcal{L}(G) &= \{n\mid [x^n,y]=[x,y]^n\text{ for all }x,y\in G\}\\
\mathcal{B}(G) &= \{n\mid [x^n,y] = [x,y^n]\text{ for all }x,y\in G\},
\end{align*}$$
called, respectively, the "exponent semigroup", the "Levi semigroup", and the "Bell semigroup" of $G$ (the sets are closed under multiplication, so they are multiplicative semigroups of the integers). Kappe proves that if $W$ is a set of integers, then the following are equivalent:
- $W=\mathcal{E}(G)$ for some group $G$.
- $W=\mathcal{B}(H)$ for some group $H$.
- $W=\mathcal{L}(K)$ for some group $K$.
She also gives conditions for a set of integers to be an exponent semigroup, reminding readers that F.W. Levi proved, in Notes on Group Theory VII. The idempotent residue classes and the mappings $\{m\}$. J. Indian Math. Soc. (N.S.) 9 (1945), 37-42, that if $M$ is the smallest positive integer in $\mathcal{E}(G)$ for which $G^M$ is abelian, then there exist pairwise relatively prime integers $q_i$, $M=q_1\cdots q_t$, $2\lt q_i$, such that $\mathcal{E}(G)$ consists precisely of the integers that are congruent to either $0$ or $1$ modulo $q_i$ for $i=1,\ldots,t$; and that if $q_1,\ldots,q_t$ are pairwise relatively prime integers, $2\lt q_i$ for each $i$, and $S$ is the set of all integers that are congruent to either $0$ or $1$ modulo $q_i$ for each $i$, then there exists a group $G$ such that $\mathcal{E}(G)=S$.