Values of integer such that a matrix equality does hold

$\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.


The following example is for $n=3.$ $$ A=\begin{bmatrix} 0 &1 &a \\ -1 &0 &0 \\ 1/a &0 &0 \end{bmatrix} $$ and $$ B = \begin{bmatrix} b & c & ca-a \\ 1-ae & d & -a^2f \\ e & f & 2af+d \end{bmatrix}. $$