Recall the definitions: $f^{-1}(B)=\{x\in X\mid f(x)\in B\}$ and $f(A)=\{f(x)\mid x\in A\}$.
Thus
$$\begin{align}& y\in f(f^{-1}(B))\\\iff &y=f(x)\text{ for some }x\in f^{-1}(B)\\\iff &y=f(x)\text{ for some }x\text{ with }f(x)\in B\\
\implies&y\in B\end{align}$$
Assume $f$ is surjective and $B\subset Y$.
Then there exists (by surjectivity) some $x\in X$ with $f(x)=y$ for every $y\in Y$, especially for every $y\in B$. This $x$ is in $ f^{-1}(B)$, thus showing that $y=f(x)\in f(f^{-1}(B))$.
On the other hand, assum ethat $f$ is not surjective, say $y\notin f(X)$. Then $f(f^{-1}(\{y\}))=f(\emptyset)=\emptyset\ne\{y\}$.