Let's first show that $f(Z(G)) \subseteq Z(H)$. Let $h \in f(Z(G))$, we want to show $h \in Z(H)$.
Since $h \in f(Z(G))$, then there exists a $g_h \in Z(G)$ such that $f(g_h) = h$. Now let $y$ be any element of $H$. In order to show that $h \in Z(H)$, we need to show that $hy = yh$ by definition of the center of a group. Since $f$ is a bijection, there exists an $x\in G$ such that $f(x) = y$.
Since $g_h \in Z(G)$, we have for $g_hg = gg_h$ for any element $g \in G$. Notice,
$$f(g_hx) = f(g_h)f(x) = hy$$
and
$$f(g_hx) = f(xg_h) = f(x)f(g_h) = yh$$
and so $hy = yh$ as desired.
Now we show $Z(H) \subseteq f(Z(G))$. Let $h \in Z(H)$. We wish to show that $h \in f(Z(G))$, in other words, that there exists $g_h \in Z(G)$ such that $f(g_h) = h$. Since $f$ is a bijection, there exists a $g \in G$ such that $f(g) = h$ so it remains to show that $g \in Z(G)$ in order for $g$ to be the $g_h$ we desire. Let $x$ be any element in $G$, we must show that $gx = xg$ in order to show $g \in Z(G)$. Since $f$ is a bijection, there exists a $y \in H$ such that $f(x) = y$. Notice that,
$$hy = f(g)f(x) = f(gx)$$
and
$$hy = yh = f(x)f(g) = f(xg),$$
thus $f(gx) = f(xg)$ and by injectivity of $f$, $gx = xg$ as desired.
Since $f(Z(G)) \subseteq Z(H)$ and $Z(H) \subseteq f(Z(G))$, we have that the two sets are equal.