Let $X$ a normed linear space. Denote with $\mathbb{F}=\mathbb{C}\;\text{or}\;\mathbb{R}$ Suppose that
(1)$\;M$ is a closed subspace of $X$;
(2)$\;x_0\in X\setminus M$;
(3)$\;d=\text{dist}(x_0, M)=\inf\{\lVert x_0-m\rVert\;:\; m\in M\}$.
Then exists $\Lambda\in X^*$ such that $$\Lambda(x_0)=d,\quad \Lambda|_M=0\quad\text{and}\quad \lVert\Lambda\rVert_{X^*}=1.$$
$\textit{Proof}$
Observe that $d>0$ since $M$ is closed. Define $M_1=\text{span}\{M,x_0\}$. Then each $x\in M_1$ can be written as $x=m_x+t_x x_0$ for same $m_x\in M$ e $t_x\in \mathbb{F}$ and since $x_0\notin M$ this representation is unique.
Define $\lambda\colon M_1\to \mathbb{F}$ as $\lambda(x)=t_xd$. Observe that $\lambda$ is linear, $\lambda|_M=0$, and $\lambda(x_0)=d.$ If $x\in M_1$ e $t_x\ne 0$, then we have that $-m_x/t_x\in M$. Then, $$\lVert x\rVert_X=\Vert t_x x_0+m_x\rVert_X=\lvert t_x\rvert \bigg\lVert x_0-\bigg(\frac{-m_x}{t_x}\bigg)\bigg\rVert_X\ge\lvert t_x\rvert d.$$
If $t_x = 0$ (so $x\in M$), this is still true.
Hence, $$\lvert\lambda(x)\rvert=\lvert{t_x}\rvert d \le\lVert x\rVert_X\quad\text{for all}\;x\in M_1.$$
Therefore $\lambda$ is continuous on $M_1$ and $\lVert\lambda\rVert_{M_1^*}\le1.$
On the other hand, exist vectors $m_n\in M$ such that $\lVert x_0-m_n\rVert_X\to d$ for $n\to \infty$.
Since $\lambda|_M=0$, we have that $$d=\lambda(x_0)=\lambda(x_0-m_n)\le\lVert x_0-m_n \rVert_X\lVert\lambda\rVert_{M_1^*}\to d\lVert\lambda\rVert_{M_1^*}.$$
Therefore $\lVert\lambda\rVert_{M_1^*}\ge 1.$ Then we have $$\lVert\lambda\rVert_{M_1^*}=1.$$
For a Corollary of Hahn Banach Theorem, exists $\Lambda\in X^*$ such that $$\Lambda|_{M_1}=\lambda\quad\text{and} \quad\lVert\Lambda\rVert_{X^*}=\lVert\lambda\rVert_{M_1^*}=1.$$
Since $x_0\in M_1$ and $M\subseteq M_1$ we have $\Lambda(x_0)=\lambda(x_0)=d$ e $\Lambda|_M=\lambda|_M=0.$
Is everything formally correct?