$\newcommand\la\lambda$

 1. 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][1], $Q^{(k)}(\la_j)=0$ for each $j$ and all $k=0,\dots,m_j-1$. 

 2. So, the $\la_j$'s are roots of $Q(z)$ with 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][2], referred to in your question, does not even mention indices.)


  [1]: https://en.wikipedia.org/wiki/General_Leibniz_rule
  [2]: https://mathoverflow.net/a/438232/36721