Take the map $f:D_8 \rightarrow D_8/\langle r\rangle \cong \mathbb{Z/2Z}$.
$Z(D_8) = \langle r^2 \rangle$ but $f(Z(G))=\{0\} \neq \mathbb{Z/2Z} =Z(\mathbb{Z/2Z})$ because $\mathbb{Z/2Z}$ is abelian.
We know that the subgroup generated by $r^2$ is of order $2$. Hence we have a map $g:\mathbb{Z/2Z} \cong \langle r^2 \rangle \rightarrow D_8 $ which is the inclusion map. So $g\circ f:D_8 \rightarrow D_8$ serves as a counter-example to the first question $f(Z(G))=Z(G)$
As for the second question whether there is an endomorphism $f:D_8 \rightarrow D_8$ such that it maps $Z(D_8)$ to some element in $D_8-Z(D_8)$? This cannot happen.
The centre of $D_8$ is $\{1,r^2\}$. Any endomorphism of $D_8$ can map $r$ to an order $4$ element or order $2$ element. Only order $4$ element in $D_8$ are $r,r^3$. Hence if $r$ is mapped to either of them we can see that $r^2$ is mapped to itself. When $r$ is mapped to any order $2$ element then $r^2$ is mapped to identity element of $D_8$ which is again in the centre. Hence in both cases $f(Z(D_8)) \subset Z(D_8)$