I'll add a proof using nets. I think that nets are often useful, since we have good intuition about sequences in metric spaces and many things work very similarly for nets in general topological spaces. (For example, we know that a metric space is compact if and only if every sequence has a convergent subsequence. If we work with topological spaces, we have a similar characterization with nets: A topological space is compact if and only if every net has a convergent subnet.)
Proof. Let $C$ be a closed subset of $X\times Y$. We want to show that $\pi[C]$ is a closed subset of $X$.
Let $(x_d)_{d\in D}$ be a net in $X$ such that each $x_d$ belongs to $\pi[C]$ and $x=\lim_{d\in D} x_d$. We want to show that $x\in\pi[C]$.
Since $x_d\in\pi[C]$, we can choose (for each $d\in D$) a point $y_d\in Y$ such that $(x_d,y_d)\in C$. Now $(y_d)_{d\in D}$ has a convergent subnet $(y_e)_{e\in E}$. (This follows from compactness of $Y$.) This means that there is an $y\in Y$ such that $y=\lim_{e\in E} y_e$.
Now we have $\lim_{e\in E} x_e = x$ and $\lim_{e\in E} y_e = y$, which implies that $\lim_{e\in E} (x_e,y_e)=(x,y)$ and $(x,y)\in C$. Therefore $x\in\pi[C]$. $\hspace{2cm}\square$
Kuratowski's theorem says that this property in fact characterizes compact spaces. Proof can be found in Engelking's book (Theorem 3.1.16) or in Henno Brandsma's post. Eric Auld asked in his comment whether this can be shown using nets. It seems that a very similar idea as in the proof using filters works also for nets, see my proof below.
I should mention that I have previously posted here a longer proof which turned out to be incorrect. (You can find it by checking revision history, if you are interested.) Luckily, Eric Auld caught the mistake
If $p_Y \colon X\times Y\to Y$ is closed for every $Y$, then $X$ is compact.
Let $D$ be a directed set and $(x_d)_{d\in D}$ be a net in $X$.
We can topologize $Y=D\cup\{\infty\}$, where $\infty\notin D$, in a natural way: All points of $D$ will be isolated. Basic neighborhoods of $\infty$ are the sets of the form $\{\infty\}\cup\{d; d\ge d_0\}$ for $d_0\in D$. (The reason that this seems to be relatively natural choice is that $x_d$ converges to $x$ in $X$ if and only if $(x_d,d)$ converges to $(x,\infty)$ in $X\times Y$.)
We want to show that the net $(x_d)_{d\in D}$ has a cluster point. Let us denote $A=\{(x_d,d); d\in D\}$. Since the map $p_Y$ is closed, we have $p_Y[\overline A]=\overline{p_Y[A]}=\overline D$, so $\infty\in p_Y[\overline A]$. This means that there is an $x\in X$ such that $(x,\infty)\in\overline A$.
Notice that basic neighborhoods of the point $(x,\infty)$ are of the form
$$U\times \{d\in D; d\ge d_0\}$$
where $d_0\in D$ and $U$ is an neighborhood of $x$.
Since every set of this form has nonempty intersection with $A$ we get that for each neighborhood $U$ of $x$ and for each $d_0$ there exists $d\ge d_0$ such that $x_d\in U$. Hence $x$ is a cluster point of the net $(x_d)_{d\in D}$. $\hspace{2cm}\square$