Let $(X, d)$ be a metric space. For a subset $A$ of $X$, let $d_A(x) := \inf_{a \in A} d(x, a)$. Let $x,y \in X$. For $b \in A$, we have $$ d_A(x) -d(y, b) = \inf_{a \in A} (d(x, a) - d(y, b)) \le d(x,b)-d(y,b) \le d(x,y). $$
So $d_A(x) -d_A(y) \le d(x,y)$. By symmetry, $|d_A(x) -d_A(y)| \le d(x,y)$ and thus the map $x \mapsto d_A(x)$ is $1$-Lipschitz. In proving this result, I have come across below theorem, i.e.,
Theorem Let $A,B$ be two closed subsets of $X$ such that $A$ is compact and $A \cap B = \emptyset$. Then the map $f:X \to \mathbb R$ defined by $$ f(x) := \frac{d_A(x)}{d_A(x)+d_B(x)} \quad \forall x\in X. $$ is Lipschitz such that $f(A)=1$ and $f(B)=0$.
Could you have a check on my below attempt?
Proof It's clear that $f(A)=1$ and $f(B)=0$. Notice that $d_A(x)+d_B(x) \ge d(A,B) := \inf\{d(a,b) : a\in A, b\in B\}>0$ because $A$ is compact, $B$ is closed, and $A \cap B = \emptyset$. Fix $x,y\in X$. Then $$ \begin{align} |f(x)-f(y)| &= \left | \frac{d_A(x)}{d_A(x)+d_B(x)} - \frac{d_A(y)}{d_A(y)+d_B(y)} \right | \\ &= \frac{|d_A(x) d_B(y) - d_A(y) d_B(x)|}{[d_A(x)+d_B(x)][d_A(y)+d_B(y)]} \\ &= \frac{|d_A(x) [d_B(y)-d_B(x)] + d_B(x) [d_A(x)-d_A(y)]|}{[d_A(x)+d_B(x)][d_A(y)+d_B(y)]} \\ &\le \frac{d_A(x) |d_B(y)-d_B(x)| }{[d_A(x)+d_B(x)][d_A(y)+d_B(y)]} + \frac{d_B(x) | d_A(x)-d_A(y)|}{[d_A(x)+d_B(x)][d_A(y)+d_B(y)]} \\ &\le \frac{d_A(x) d(x,y) }{[d_A(x)+d_B(x)][d_A(y)+d_B(y)]} + \frac{d_B(x) d(x,y)}{[d_A(x)+d_B(x)][d_A(y)+d_B(y)]} \\ &\le \frac{d(x,y) }{d_A(y)+d_B(y)} + \frac{d(x,y)}{d_A(y)+d_B(y)} \\ &\le \frac{2d(x,y) }{d(A,B)} . \end{align} $$
This completes the proof.
As per request, I post the comment as an answer.
The proof is sound. Yes, we need (sequential) compactness to obtain the existence of a limit point in $A$, which is then a limit point to both, yielding a contradiction. I would just change the assertion to $A,B$ such that $d(A,B)>0$. That's intuitive, too, and closedness, compactness are only required to get the positive distance. Clearly, the altered result is significantly stronger, and the Theorem as stated in the question is then an immdiate corollary. But of course, that's a matter of taste.