Q:

Topological conditions forcing continuity

Let $X$, $Y$, and $Z$ be topological spaces.  Let $f:X \rightarrow Y$.  Further assume that for every continuous function $g:Y \rightarrow Z$, $g \circ f$ is continuous.  
Question: Under what conditions on the topology of $Y$ and/or $Z$ can we conclude that $f$ must then be continuous?
This is easily achieved if $Y$ is (essentially) homeomorphic with $Z$, but this seems like drastic overkill.   
To me, this seems like some kind of 'universal property' for the continuity of $f$; or maybe some kind of generalized "uniformly continuous" condition?  Note: original question due to Nick James, but he's not a big web user, so I am asking on his behalf.

A:

It's possible to find a sufficient condition without putting any restraint on the spaces $X$ or $Y$.
Let $Z$ be the Sierpinski space, that is $Z$ has $\{0,1\}$ as a base set, and $\tau = \{\emptyset, \{0\}, \{0,1\}\}$ as a topology.
If $f: X\to Y$ is not continuous, then there is $V\subseteq Y$ open such that $f^{-1}(V)$ is not open in $X$. Defining $g_V: Y\to Z$ as mapping $V$ to $0$ and $Y\setminus V$ to $1$ we immediately see that $g_V\circ f: X \to Z$ is not continuous.
An interesting (and probably solved) question would be how to characterise the spaces $Z$ that have this universal property for all spaces $X, Y$.

