The problem is to find all integer values $n\geq 2$ such that there exist two non-zero $n\times n$ real matrices $A,B$ satisfying $$A^2B-BA^2=A.$$
For $n=2$ such matrices do not exist. Therefore, I am a little bit puzzled on the path I should follow: that there are no such matrices for any $n$, or to prove that such matrices exist, at least for some values of $n$ (maybe related to the parity of $n$...). I have managed to prove that if such matrices exist, then $\hbox{tr}(A)=0$ and $\det(A)=0$.
$\textbf{Proposition 1}$. $A$ is nilpotent.
$\textbf{Proof}.$ $A^2B-BA^2$ commute with $A^2$. Then (Jacobson) $A^2B-BA^2=A$ is nilpotent.
$\textbf{Proposition 2}$. There are non-zero solutions only when $n\geq 3$;
$\textbf{Proof}$. When $n=2$, $A^2=0$ and $A=0$. No solutions.
When $n=3$, a particular solution is
$A_3=J,B_3=\begin{pmatrix}0&0&0\\-1&0&0\\0&1&0\end{pmatrix}$, where $J$ is the nilpotent Jordan block of dimension $3$.
When $n>3$, a particular solution is
$A=diag(A_3,0_{n-3}),B=diag(B_3,0_{n-3})$.
Note that if $(A,B)$ is a solution, then $(A,B+uI_n)$ is also a solution.