There's a flavor of Jacobson's Lemma here and the implication that $n$ is even holds in any field where Newton's Identities have maxmal effect-- i.e. any field of characteristic zero or when $n\lt \text{char } \mathbb F $.
(Trivial note: OP's problem statement cannot exist when $n=1$ since the commutator would be zero.)
Let $C:=AB-BA$ be the commutator. And consider
$C\mapsto AC + CA $
$= A\big(AB-BA\big) + \big(AB-BA\big)A=A^2B-ABA +ABA -BA^2=\big(-B^2\big)B-B\big(-B^2\big) = \mathbf 0$
$\implies AC=-CA$
$\implies AC^2 = (AC)C=(-CA)C= -C(AC)=-C(-CA)=C^2A$
and by induction $A$ commutes with all even powers of $C$. Now examine the trace:
for odd $r\in \mathbb N$
$\text{trace}\Big(C^r\Big)$
$= \text{trace}\Big( C^{r-1} C\Big)$
$= \text{trace}\Big( C^{r-1}\big({AB} - {BA}\big)\Big) $
$= \text{trace}\Big(C^{r-1}{AB} - C^{r-1}{BA}\Big) $
$= \text{trace}\Big(C^{r-1}{AB}\Big) - \text{trace}\Big(C^{r-1}{BA}\Big) $
$= \text{trace}\Big(AC^{r-1}B\Big) - \text{trace}\Big(C^{r-1}{BA}\Big) $
$= \text{trace}\Big(C^{r-1}BA\Big) - \text{trace}\Big(C^{r-1}{BA}\Big) $
$=0$
Finally, write out the characteristic polynomial for $C$
$p(x) = x^n + a_{n-1}x^{n-1} + a_{n-2}x^{n-2} +... + a_{1}x^{1}+ a_0$
where $a_n =1$ since we've defined the characteristic polynomial to be monic and $a_{n-1} =0 = -\text{trace}\big(C\big)$
which is a Base Case for the inductive hypothesis on $r$, that $a_{n-r
} = 0$ for positive odd $r\leq n$. Applying Newton's Identities:
$a_{n-r} = -\frac{1}{r} \sum_{j=1}^{r} a_{n-r + j}\cdot \text{trace}\big(C^j\big) =0\text{ when r is odd}$
since $\text{trace}\big(C^j\big)=0$ for odd $j$ (proven above) and $a_{n-r + j}=0$ when $j$ is even (strong induction hypothesis)
For the case of $r =n$, we know $\det\big(C\big)\neq 0\implies a_{n-n}=a_0\neq 0\implies n\text{ is even}$