An application (question) of Tietze Extension Theorem Below is a question, followed by a partial solution that I am confused about.

Let $X$ be a T$_4$ space and $M\subseteq X$ be closed. Let $\mathbb{S}^1$ be the unit circle with the subspace topology. Suppose that $f\colon M\to\mathbb{S}^1$ is a continuous such that $f[M]$ is a closed proper subset of $\mathbb{S}^1$. Show that there exists a continous function $\hat{f}\colon X\to\mathbb{S}^1$ such that $\hat{f}\vert_{M}=f$.

So, I figured I could just directly apply Tietze Extension Theorem here, but when I checked the solution this was not the case. My question is, why can't I just apply Tietze Extension Theorem here? Is it because Tietze Extension Theorem requires $f$ to map to $\mathbb{R}$? For reference, the given solution shows that there exists an open arc $\gamma$ in $\mathbb{S}^1$ such that $\gamma\subseteq\mathbb{S}^1\setminus f[M]$ hence $f[M]\subseteq\mathbb{S}^1\setminus\gamma$. Then goes on to say, $\mathbb{S}^1\setminus\gamma$ is a non-empty closed arc in $\mathbb{S}^1$, thus homeoremorphic to the interval $[0,1]$. Hence, by Tietze Extension Theorem there exists a continuous function $\hat{f}\colon X\to\mathbb{S}^1\setminus\gamma\subseteq \mathbb{S}^1$ such that $\hat{f}\vert_{M}=f$.

To add, I though I could simply say: "By Tietze Extension Theorem, there is a continuous function $\hat{f}\colon X\to\mathbb{S}^1$ such that $\hat{f}\vert_M=f$." However, based on the given solution, I can't just say this. So again, my question really is, why can't I just say that?
 A: Tietze extension theorem states:

Let $X$ be a $T_4$ space, $M\subseteq X$ a closed subset and $f:M\to\mathbb{R}$ a continuous function. Then there exists a continuous function $F:X\to\mathbb{R}$ such that $F_{|M}=f$. Moreover $F$ can be chosen in such a way that $sup(|f(m)|:\ m\in M)=sup(|F(x)|:\ x\in X)$.

Note that there's "$\mathbb{R}$" on the right side. This is no accident. It doesn't work for an arbitrary space. It does work for some but not all.
The first observation is that the supremum property implies that we can replace $\mathbb{R}$ with $[0,1]$ in the theorem. But we cannot replace $\mathbb{R}$ with $S^1$ without some additional assumptions.
Here's a counterexample: consider $D=\{v\in\mathbb{R}^2 :\ \lVert v\rVert\leq 1\}$. Note that $S^1\subseteq D$ is a closed subset. Then consider the identity $id:S^1\to S^1$, $id(x)=x$. Can this $id$ be extended to a $D\to S^1$ map? This is the famous "is $S^1$ a retract of $D$?" question and the answer is "no", which is a consequence of Brouwer Fixed Point Theorem.
The reason why it works in your case is because $f[M]$ is a closed proper subset of $S^1$. This is the additional assumption that makes a difference. Such subsets are always contained in some arc $A\subseteq S^1$. And arcs are homeomorphic to $[0,1]$. By using such a homeomorphism, its inverse and Tietze for $[0,1]$ we can construct the extension we are looking for.
A: Your idea of applying Tietze is OK, but needs a small tweak:
Realise that for any $p \in \Bbb S^1$, we have that $\Bbb S^1\setminus \{p\} \simeq \Bbb R$ (using the stereographic projection from $p$) and if we have $f: M \to \Bbb S^1$ non-surjective we can pick any $p\in \Bbb S^1 \setminus f[M]$, and a homeomorphism $h: \Bbb S^1 \setminus \{p\} \to \Bbb R$ and consider $h \circ f: M \to \Bbb R$ instead, which is wel-defined (as $p$ is not in $f[M]$) and continuous.
By Tietze, this has a continuous extension $g: X \to \Bbb R$ (so $g = h \circ f$ on $M$) and then we can define $\bar{f}: X \to  \Bbb S^1$ by $\bar{f} = h^{-1} \circ g$, which is of course continuous as a composition of continuous maps.
This extends $f$ as $$\forall x \in M: \bar{f}(x) = h^{-1}(g(x)) = h^{-1}(h(f(x))) = f(x)$$
You cannot expect that all maps into $\Bbb S^1$ can be extended from a closed subspace to the whole space, this turns out to be equivalent to $\dim(X) \le 1$, where dim is the covering dimension of $X$. And we cannot extend the identity from $\Bbb S^1 \subseteq \Bbb D^2$ to the whole disk $\Bbb D^2$, because that would contradict the so-called non-retraction theorem.
Spaces $Y$ as a codomain for which we can always extend from a closed subspace to the whole space are called AR’s (absolute retracts), and these include all spaces $\Bbb R^n$ and many other linear spaces and convex subsets of them.
