Solution (source code)

= Solution

This is always true for metric spaces. Let $x_n\to x$. If $f(x_n)$ did not converge to $f(x)$, some subsequence would remain at least $\varepsilon>0$ from $f(x)$. Compactness of $Y$ gives a further subsequence
$$
f(x_{n_k})\to y.
$$
Then $(x_{n_k},f(x_{n_k}))\to(x,y)$. The graph is closed, so $(x,y)$ belongs to it and $y=f(x)$, contradicting the $\varepsilon$ separation. Thus $f(x_n)\to f(x)$ for every convergent sequence, and the equivalence proved above makes $f$ continuous. This is the <closed-graph criterion with compact codomain>.