Let $K$ be an algebraically closed field, let $A$ be an $n$ by $n$ matrix with coefficients in $K$, let $X$ be an indeterminate, let $f$ be in $K[X]$, let $L$ be the set of eigenvalues of $A$, let $M$ be the set of eigenvalues of $f(A)$, and for $\lambda\in L,\mu\in M$ let $E_\lambda,F_\mu$ be the respective generalized eigenspaces.
As the OP noticed, we have $f(L)\subset M.$
For $\mu$ in $M$ put
$$
S_\mu:=\bigoplus_{\lambda\in f^{-1}(\mu)}E_\lambda\subset K^n.
$$
To answer the question, it suffices to show
$$(1)\quad F_\mu=S_\mu\quad\forall\ \mu\in M.$$
This will imply in particular $f(L)=M$.
We claim
$$(2)\quad E_\lambda\subset F_{f(\lambda)}\quad\forall\ \lambda\in L.$$
We prove that (2) implies (1). By (2) we have $S_\mu\subset F_\mu$ for all $\mu$ in $M$. As we also have
$$
\sum_{\mu\in M}\ \dim F_\mu=n=\sum_{\mu\in M}\ \dim S_\mu,
$$
we get (1).
We're left with proving (2). Let $\lambda$ be in $L$. As $A$ and $f(A)$ preserve $E_\lambda$, they induce endomorphisms $A_\lambda$ and $f(A)_\lambda=f(A_\lambda)$ of $E_\lambda$. Let $\nu$ be an eigenvalue of $f(A)_\lambda$. It suffices to show $\nu=f(\lambda)$. We can assume that $f$ is non constant and monic.
We have
$$
f(X)-\nu=(X-a_1)\cdots(X-a_d)
$$
for some $a_1,\dots,a_d$ in $K$, and thus
$$
f(A)_\lambda-\nu=f(A_\lambda)-\nu=(A_\lambda-a_1)\cdots(A_\lambda-a_d).
$$
This endomorphism being singular and $\lambda$ being the only eigenvalue of $A_\lambda$, one of the $a_i$ is equal to $\lambda$, yielding $\nu=f(\lambda)$, as required.