Henno’s argument is probably the slickest, but one can also work pointwise, either directly or, if one already has those characterizations of continuity, with nets or filters.

Suppose that $f$ is not continuous. Then there is some point $x_0\in X$ at which $f$ fails to be continuous. If $y_0=f(x_0)$, this means that there is an open nbhd $U$ of $y_0$ such that if $V$ is an open nbhd of $x_0$, there is a point $x_V\in V$ such that $f(x_V)\notin U$. Let $$A=\{x_V:V\text{ is an open nbhd of }x_0\}\;.$$

Clearly $x_0\in\overline{A}$, and $f[A]\subseteq Y\setminus U$. Moreover, $Y\setminus U$ is closed, so $\overline{f[A]}\subseteq Y\setminus U$, and hence

$$y_0\in f[\overline{A}]\subseteq\overline{f[A]}\subseteq Y\setminus U\;,$$

contradicting the choice of $U$.

Those who like nets may notice that $A$ actually **is** a net, over the directed set $\langle\mathscr{N}(x_0),\supseteq\rangle$, where $\mathscr{N}(x_0)$ is the family of open nbhds of $x_0$, and the argument shows that $f$ doesn’t preserve the limit of this net. (I could of course just as well have used the nbhd filter at $x_0$, instead of using only open nbhds.)

Those who prefer filters may modify this to consider the filter $$\mathscr{F}=\{V\cap f^{-1}[Y\setminus U]:V\in\mathscr{N}(x_0)\}$$ instead.