This question already has an answer here:
Let $G=\operatorname{Gr}(f)$. In this case the easiest way to show that $G$ is closed in $X\times Y$ is to show that its complement is open, so let $\langle x,y\rangle\in(X\times Y)\setminus G$. Since $\langle x,y\rangle\notin G$, $y\ne f(x)$. Thus, $y$ and $f(x)$ are distinct points in $Y$. And $Y$ is Hausdorff, so there are disjoint open sets $U$ and $V$ in $Y$ such that $y\in U$ and $f(x)\in V$. Finally, $f$ is continuous, so there is an open nbhd $W$ of $x$ such that $f[W]\subseteq V$.
Up to here I’ve just done what comes naturally: I’ve used the hypotheses in the most obvious way without really thinking about where I’m going. I’m trying to show that $\langle x,y\rangle$ has an open nbhd contained in $(X\times Y)\setminus G$; do I have an open nbhd of $\langle x,y\rangle$ hanging about anywhere? Yes: by definition of the product topology, $W\times U$ is an open nbhd of $\langle x,y\rangle$ in $X\times Y$. If I’m lucky, this nbhd $W\times U$ will turn out to be disjoint from $G$, showing that $\langle x,y\rangle$ is not in the closure of $G$. And since $\langle x,y\rangle$ was an arbitrary point of $(X\times Y)\setminus G$, this would show that $(X\times Y)\setminus G$ is open and hence that $G$ is closed.
Let $\langle z,f(z)\rangle$ be any point of $G$. If $z\notin W$, then clearly $\langle z,f(z)\rangle\notin W\times U$. If $z\in W$, then $f(z)\in V$, so $f(z)\notin U$, and therefore $\langle z,f(z)\rangle\notin W\times U$. Thus, in all cases $\langle z,f(z)\rangle\notin W\times U$, and it follows that $(W\times U)\cap G=\varnothing$. Thus, each point of $(X\times Y)\setminus G$ has an open nbhd disjoint from $G$, and $G$ is therefore closed.