I am reasking a year-old math.stackexchange.com question asked by someone else.

(For my needs every space $X$ and $Y$ will be Polish---that is a completely separably metrizable space.)

The Tietze extension theorem says that if $X$ is a Polish space (even a normal space) and $Y=\mathbb{R}^n$, then a continuous function $f:C \rightarrow Y$ on a closed set $C \subseteq X$ can be extended to a continuous function $g:X \rightarrow Y$.

It seems important to the theorem in general that $Y = \mathbb{R}^n$, however there are some examples of pairs $X,Y$ where the theorem also holds. For example, it is true if $X, Y \in \{2^\mathbb{N},\mathbb{N}^\mathbb{N}\}$. (Although, other pairs like $X=\mathbb{R}, Y = 2^\mathbb{N}$ do not hold.)

Is there a characterization of the pairs $X,Y$ (or $X,Y,C$) for which the Tietze extension theorem holds?

If not, what extensions are known, especially those that include my $2^\mathbb{N}$ example above?

One motivation for asking this question is Lusin's theorem: If $(X,\mathcal{B},P)$ is a Borel probability measure on a Polish space $X$ (even a Radon measure on a finite measure space) and $f:X \rightarrow Y$ is a measurable map (again $Y$ is Polish, or even second countable), then for all $\varepsilon > 0$, there is a closed set $C$ of measure $1-\varepsilon$ such that $f$ is continuous on $C$.

If $Y$ is $\mathbb{R}^n$, we can apply the Tietze extension theorem to find some continuous $g:X \rightarrow Y$ such that $g = f$ on $C$. Wikipedia currently (12 July 2013) has a **false statement** that for any locally compact $X$ we can find such a continuous $g:X \rightarrow Y$. For a counterexample, take $X=[0,1]$ and $Y=2^\mathbb{N}$ and $f$ to be the bit representation of the reals.

I am interested in which cases this stronger version of Lusin's thoerem (with the continuous $g:X \rightarrow Y$) holds.