Find all positive integers $n$ for which there exist two square matrices of size $n$, with real entries, shall we denote them by A and B, such that $A^2B-BA^2=A$ and $A\neq O_n$ and $B\neq O_n$.
So far, I have obtained that $A^{2m}B-BA^{2m}=mA^{2m-1}$ and $tr(A^{2m-1})=0$, for every $m \geq 1$. I believe this problem can be dealt with by (wisely) multiplying multiple matricial relationships, at left and at right with A, B or powers of them, however this is only a guess.
As others have observed, it follows that $A$ is nilpotent. Fiddling with the entries, $$ A=\pmatrix{0&1&0\\ 0&0&1\\0&0&0},\quad B=\pmatrix{0&0&0\\ -1&0&0\\0&1&0} $$ is a valid pair. Hence for all $n\ge3$ such matrix pairs exist.
For $n\le 2$, such pairs do not exist: then $A$ nilpotent implies $A^2=0$, and $A=0$ from the equation.