# On commutator relations and nilpotency class of a $p$-group

Suppose $G$ is a $p$-group, and $x,y\in G$ be arbitrary.

If the commutator $[x,y]$ commutes with both $x$ and $y$, then the subgroup $\langle x,y\rangle$ has nilpotency class $\leq 2$.

Question: Suppose, $G$ is a $p$-group such that $[x,y]$ commutes with both $x$ and $y$ and this is true for all $x,y\in G$. Does it follow that the whole group $G$ has nilpotency class $\leq 2$?

The answer appears to be no. A nilpotent group in which every $2$-generator subgroup has class $2$ has class at most $3$. There is an example of order $3^7$ of such a group of class $3$. However, for $n \ge 3$, if all $n$-generator subgroups of $G$ have class $n$, then so does $G$. These results are apparently due to Levi and Heineken. See here.