Let me try to answer these questions under the assumption that $Y$ is $T_1$.

We start with a set $E$ along with a filter $\mathcal F\in\mathcal P(E)$. We can then cook up a topological space $X$ with underlying set $\{x\}\sqcup E$ with topology given by the discrete topology $E^\delta$ on $E$, and $\{x\}\sqcup U$ for every $U\in\mathcal F$. It follows from definition that, for every topological space $Y$, a map $f\colon X\to Y$ is continuous if and only if $f\rvert_E\colon E\to Y$ *tends to* $f(x)\in Y$ along the filter $\mathscr F$, namely, for every neighborhood $V$ of $f(x)\in Y$, there exists a set $U\in\mathcal F$ such that $f(U)\subseteq V$. In short, the continuity captures the convergence along the filter.

What about the graph of a map $f\colon X\to Y$ being closed? Here we need the assumption of $Y$ being $T_1$, so that we only have to test the existence of open neighborhoods at every point $(x,y)\in X\times Y$ where $y$ runs through all points of $Y\setminus f(x)$. Unwinding the definitions, it is equivalent to saying that, there exists a subset $U\in\mathcal F$ and an open neighborhood $V$ of $y\in Y$ such that

- $y\not\in V$; and
- for every $x\in U$, we have $f(x)\not\in V$.

Equivalently, it is saying that $y$ is not a cluster point of $f$ along $\mathcal F$.

A positive answer to Question 1. It is known that, a topological space is compact if and only if every filter on the underlying set admits a cluster point. We assume that $Y$ is non-compact, thus it is non-empty, and there exists a filter on $Y$ which does not admit any cluster point. We fix such a filter $\mathcal F$, an arbitrary point $y\in Y$, and let $E=Y$ be a set endowed with the filter $\mathcal F$. We now define $f\colon X\to Y$ by $f(x)=y$ and $f\rvert_E=\operatorname{id}$. The previous analysis shows that $f$ is not continuous but its graph is closed.

A sketch of a negative answer to the second question. More precisely, we have

**Proposition.** For *every* topological space $X$, there exists a non-compact but Hausdorff topological space $Y$ such that every map $X\to Y$ with closed graph is continuous.

Roughly speaking, the compactness of $Y$ can be more complicated than what a fixed topological space $X$ can see. To see this, we introduce a slightly "quantitative" version of compactness:

**Definition.** Let $\kappa$ be a strong limit cardinal (i.e., for every $\lambda<\kappa$, we have $2^\lambda<\kappa$). We say that a topological space $X$ is *$\kappa$-compact* if, for every set $E$ with $\lvert E\rvert<\kappa$ and every filter $\mathcal F$ in $E$ (note: $\kappa$ being strong limit implies that $\lvert\mathcal F\rvert\le 2^{\lvert E\rvert}<\kappa$), every map $E\to X$ admits a cluster point along $\mathcal F$.

**Update:** This definition is equivalent, by the axiom of choice, to the following simpler one: every filter *base* $\mathcal F$ on $X$ with $\lvert\mathcal F\rvert<\kappa$ admits a cluster point in $X$. The usual proof shows that this $\kappa$-compactness is equivalent to the open-cover condition that every open cover of size $<\kappa$ contains a finite subcover.

**Lemma.** Let $\kappa$ be a strong limit cardinal and $Y$ a $\kappa$-compact topological space. Then for every topological space $X$ with $\lvert X\rvert<\kappa$, the projection $X\times Y\to X$ is closed.

The usual proof leads to

**Corollary.** Let $\kappa$ be a strong limit cardinal and $Y$ a $\kappa$-compact topological space. Then for every topological space $X$ with $\lvert X\rvert<\kappa$, a map $X\to Y$ is continuous if and only if its graph is closed.

Now in order to see the Proposition above, it suffices to construct a $\kappa$-compact non-compact topological space for a chosen strong limit cardinal $\kappa>\lvert X\rvert$. If I am not mistaken, we can take an ordinal $\lambda$ with cofinality greater than $\kappa$, with the order topology.

everynon-discrete space $X$), and you say so at the end, but it should be part of the initial question. Or maybe your question is whether there issome$X$ for which the implication holds (for all $Y$), or whether the hypothesis forall$X$ implies that $Y$ is compact? $\endgroup$