$\newcommand\la\lambda$
Let $g(z)$ denote some branch of $\sqrt z$, so that $Q(z)=P(z)^2-g(z)^2$ and $P^{(k)}(\la_j)=g^{(k)}(\la_j)$ for each $j$ and all $k=0,\dots,m_j-1$, where the $\la_j$'s are the distinct eigenvalues of $A$ and the $m_j$'s are their multiplicities. Then, by the Leibniz rulee, $Q^{(k)}(\la_j)=0$ for each $j$ and all $k=0,\dots,m_j-1$.
So, the $\la_j$'s are roots of $Q(z)$ with respective multiplicities $n_j\ge m_j$ for each $j$. So, for some polynomial $R(z)$, $$Q(z)=R(z)\prod_j(z-\la_j)^{n_j}=R_1(z)\prod_j(z-\la_j)^{m_j} =R_1(z)C(z),$$ where $R_1(z):=\prod_j(z-\la_j)^{n_j-m_j}R(z)$ is a polynomial and $C(z):=\prod_j(z-\la_j)^{m_j}$ is the characteristic polynomial of $A$.
(The previous answer, referred to in your question, does not even mention indices.)