Let $X$ be a metric space and $Y$ be a compact metric space. I want to show that the graph of $f$, $G\subset X\times Y$ is closed $\iff$ $f:X\to Y$ is continuous.
I'm not sure where the compactness of $Y$ comes into play. I think I've already proven $f$ continuous $\implies G$ closed without using compactness, so I think it's supposed to be used in the other direction. Here's my attempt at $G$ is closed $\implies f$ is continuous:
Let $(x_n)\subset X$ be a sequence such that $x_n\to x\in X$. Now consider the sequence $((x_n,f(x_n)))\subset G$. Since $G$ is closed, $L=\text{lim}(x_n,f(x_n))\in G$. But $L=(\text{lim} x_n,\text{lim} f(x_n))=(x,\text{lim} f(x_n))$. So for $L$ to be in $G$, we must have $\text{lim}f(x_n)=f(x)=f(\text{lim}x_n)$. So $f$ is continuous.
Is there something wrong with my solution? Where is compactness of $Y$ needed?
Closedness of the graph only needs that $Y$ is Hausdorff and nothing on $X$ (so the assumptions are somewhat overkill for that direction).
The limit $L$ of $(x_n, f(x_n))$ need not exist. But $(f(x_n))_n$ is a sequence in a compact space $Y$, so there is a subsequence $(f(x_{n_k}))_k \rightarrow y \in Y$.
Then $((x_{n_k}, f_{n_k}))_k$ is a sequence in $G$, and converges to $(x,y)$ (coordinate-wise convergence in the product), so $(x,y) \in G$ and so $y = f(x)$. You'd think you're almost there, but we have not shown that $f(x_n)$ converges to $f(x)$, only a subsequence. So I think then you're not quite finished with what you had to show.
So I think a better proof starts by assuming a contradiction: let $x_n \rightarrow x$ and suppose (for a contradiction) that $f(x_n) \nrightarrow f(x)$. The latter means that there is an $\varepsilon > 0$ such that $Y \setminus B(f(x), \varepsilon)$ contains infinitely many $f(x_n)$, so we can find a subsequence $x_{n_k}$ (that still converges to $x$) such that $d(f(x_{n_k}, f(x)) \ge \varepsilon$. The latter subsequence $f(x_{n_k})$ is a sequence in the compact $Y \setminus B(f(x),\varepsilon)$ so has a convergent subsubsequence $(f(x_{n_{k_l}}))_l$ that converges to some $ y \in Y \setminus B(f(x),\varepsilon)$. As before $(x_{n_{k_l}},f(x_{n_{k_l}}))_l$ converges to $(x,y)$ so $(x,y) \in G$ and $y = f(x)$, which cannot be, as $d(y,f(x)) \ge \varepsilon$.
So that shows that $f(x_n) \rightarrow f(x)$ and $f$ is continuous.
I think this can be made to work in a non-metric setting using nets, subnets and accumulation points, but I'll stop here, as the question and its proof were specifically for metric spaces.