Since $A^n=0$ but $A^{n-1}\neq0$, the minimal polynomial of $A$ must be $x^n$. In particular, no smaller power of $A$ vanishes. Because the characteristic polynomial also has degree $n$, it too must be $x^n$. In other words, $A$ is nilpotent of index exactly $n$, and its minimal and characteristic polynomials coincide—so $A$ is “non-derogatory.”
Equivalently, over $\mathbb{Q}$ one can put $A$ into a single $n\times n$ Jordan block for the eigenvalue $0$. Concretely, there is an invertible $P\in GL_n(\mathbb{Q})$ so that
$$
A \;=\; P\,J\,P^{-1},
\quad
J \;=\;
\begin{pmatrix}
0 & 1 & 0 & \cdots & 0\\
0 & 0 & 1 & \cdots & 0\\
\vdots & & \ddots & \ddots & \vdots\\
0 & 0 & \cdots & 0 & 1\\
0 & 0 & \cdots & 0 & 0
\end{pmatrix}.
$$
Because $AB=BA$, if we set $B' = P^{-1}BP$, then $J\,B' = B'\,J$. Writing $B'=(b_{ij})$, one checks that this forces
$$
b_{i,j-1} \;=\; b_{\,i+1,j}
\quad
\text{and}\quad
b_{k1}=0 \text{ for }k>1,\quad
b_{n,j-1}=0\text{ for }j>1.
$$
In plain language, each super-diagonal of $B'$ has a constant entry, and every entry strictly below the main diagonal must be zero. Thus
$$
B' \;=\;
\begin{pmatrix}
c_0 & c_1 & c_2 & \cdots & c_{n-1}\\
0 & c_0 & c_1 & \cdots & c_{n-2}\\
0 & 0 & c_0 & \cdots & c_{n-3}\\
\vdots & \vdots & & \ddots & \vdots\\
0 & 0 & 0 & \cdots & c_0
\end{pmatrix},
$$
with each $c_k\in\mathbb{Q}$. But that is exactly
$$
c_0 I + c_1 J + c_2 J^2 + \cdots + c_{n-1} J^{\,n-1}.
$$
Since $J^n=0$, the polynomial
$$
F(x) \;=\; c_0 + c_1 x + \cdots + c_{n-1}x^{\,n-1}
$$
satisfies $B' = F(J)$. Going back to the original basis,
$$
B \;=\; P\,B'\,P^{-1} \;=\; P\,F(J)\,P^{-1}.
$$
But $J = P^{-1}AP$, so $F(J) = P^{-1}F(A)\,P$. Hence
$$
B \;=\; F(A),
$$
and $F$ has rational coefficients of degree at most $n-1$.
Once you realize $A$ is a single $n$-block Jordan nilpotent, any matrix commuting with it must be a polynomial in $J$; conjugating back shows $B$ is that same polynomial in $A$. Therefore
$$
B \;=\; F(A),
\quad F(x)\in \mathbb{Q}[x],\;\deg F < n,
$$
as claimed.