Is any necessary and sufficient criteria for a topological space to be compact using continuous functions? We know that there is a criteria for a space being connected using continuous functions, namely,

A topological space $(X,\tau)$ is said to be connected if for any continuous function $f:X\to\{\pm 1\}$ (where the topology on $\{\pm 1\}$ is the subspace topology that it inherits as a subspace of the topological space $\mathbb{R}$ with usual topology) is constant.

I was wondering if there is any necessary and sufficient criterion for a topological space to be compact using continuous functions. More specifically, what I want is a definition of the form,

A topological space $(X,\tau)$ is said to be compact if for any continuous function $f:X\to Y$ (where $Y$ is the topological space with property $P$) satisfies property $Q$.  

Is there any such criteria?
 A: Here is a negative answer if you impose certain restrictions.  Let us suppose we only care about Hausdorff spaces, so we require that the space $Y$ is Hausdorff but only require that the criterion work if $X$ is Hausdorff.  Then if you require the criterion to involve just one space $Y$ and that property $Q$ cannot involve the topology on $X$ (i.e., it depends only on the underlying map of sets $X\to Y$), there is no such criterion.
To prove that no such criterion exists, I will prove the following statement.  For any Hausdorff space $Y$, there exist two different Hausdorff spaces $X$, $X'$ on the same underlying set such that $X$ is compact and $X'$ is not, and a map $f:X\to Y$ is continuous iff it is continuous as a map $X'\to Y$.
(Actually, the argument will only require that limits of sequences in $Y$ are unique, which is weaker than $Y$ being Hausdorff.)
To prove this, let $\kappa$ be a regular uncountable cardinal such that $\kappa>|Y|$.  Let $X=(\kappa+1)\times(\omega+1)$ with the product topology, and let $X'$ be the same set with the topology generated by the product topology together with the set $\{(\kappa,\omega)\}\cup(\kappa+1)\times\omega$.  Then $X$ is compact Hausdorff, and $X'$ is not compact since it has a strictly finer topology than a compact Hausdorff topology.  Since the topology in $X'$ is finer than the topology on $X$, clearly a continuous map $X\to Y$ is also continuous as a map $X'\to Y$.
Conversely, suppose $f:X'\to Y$ is continuous.  Since the topologies of $X$ and $X'$ agree on the complement of the point $(\kappa,\omega)$, it suffices to show $f$ is continuous at $(\kappa,\omega)$ in the topology of $X$.
Suppose $n<\omega$.  Since $f$ is continuous at the point $(\kappa,n)$ and $Y$ is $T_1$, for each $y\in Y$ such that $y\neq f(\kappa,n)$, there exists $\beta_{n,y}<\kappa$ such that $f(\alpha,n)\neq y$ for all $\alpha>\beta_{n,y}$.  Now define $$\beta=\sup\{\beta_{n,y}:n<\omega,y\neq f(\kappa,n)\}.$$  Since $\kappa$ has cofinality greater than $|\omega\times Y|$, $\beta<\kappa$.  Thus we have found a single $\beta<\kappa$ such that for all $n<\omega$ and all $\alpha>\beta$, $f(\alpha,n)=f(\kappa,n).$  Write $g(n)=f(\kappa,n)$.
Now for any $\alpha\in\kappa+1$ (including $\alpha=\kappa$), $(\alpha,n)$ converges to $(\alpha,\omega)$ in $X'$ as $n\to\infty$.  Continuity of $f$ now implies that for any $\alpha>\beta$ (including $\alpha=\kappa$), $f(\alpha,\omega)$ is a limit of the sequence $g(n)$.  Since $Y$ is Hausdorff, this limit is unique, and so actually $f(\alpha,\omega)$ takes the same value for all $\alpha>\beta$, which we will call $g(\omega)$.
We have thus seen that the restriction of $f$ to the set $U=\{\alpha:\alpha>\beta\}\times(\omega+1)$ is just the composition of the projection onto $\omega+1$ with a certain map $g:\omega+1\to Y$.  Morever, $g$ is continuous, since $g(n)$ converges to $g(\omega)$.  It follows that $f$ is continuous with respect to the product topology on $U$.  Since $U$ is a neighborhood of $(\kappa,\omega)$ in $X$, it follows that $f$ is continous at $(\kappa,\omega)$ in the topology of $X$.  Thus $f$ is continuous as a map $X\to Y$.
(The spaces used in this proof are variants of the Tychonoff plank, which is a famous source of counterexamples in general topology.)

On the other hand, here is a positive answer if you allow a family of different spaces $Y$ (but a reasonably simple such family).  Let $S=\{0,1\}$, topologized such that $\{1\}$ is open but $\{0\}$ is not.  We write $\mathbf{0}\in S^I$ for the constant function $I\to S$ taking value $0$, for any set $I$.  Let the patch topology on $S^I$ be the product topology with respect to the discrete topology on $\{0,1\}$.  Then:

A space $X$ is compact iff whenever $I$ is any set and $f:X\to S^I$ is a continuous map such that the point $\mathbf{0}$ is in the closure of the image of $f$ with respect to the patch topology, $\mathbf{0}$ is in the image of $f$.

(So the spaces $Y$ are $S^I$ for any set $I$, and condition $Q$ is that the image of $f$ is "closed at $\mathbf{0}$ with respect to patch topology".)
The proof is just a matter of unravelling definitions.  A continuous map $f:X\to S$ is just the characteristic function of an open set, so a continuous map $f:X\to S^I$ is a collection of open subsets $U_i$ of $X$ indexed by $I$.  To say that $\mathbf{0}$ is in the closure of the image of $f$ with respect to the patch topology is to say that no finite subcollection of the $U_i$ covers $X$ (since a patch neighborhood of $\mathbf{0}$ just consists of requiring that some finite collection of the indices are $0$).  To say that $\mathbf{0}$ is in the image of $f$ is to say that the $U_i$ do not cover $X$.  So the criterion says exactly that any open cover has a finite subcover.
