Uniform density of Lipschitz maps is space of continuous function — for general metric spaces Let $X$ and $Y$ be metric space, $X$ be compact, $C(X,Y)$ denote the set of continuous functions from $X$ to $Y$ with uniform convergence on compacts topology, and $\operatorname{Lip}(X,Y)$ denote the subspace of Lipschitz functions from $X$ to $Y$.  Under what conditions is $\operatorname{Lip}(X,Y)$ a dense subset of $C(X,Y)$?

I expect that there should be some “topological compatibility condition” between $X$ and $Y$, but this is purely (and likely unfounded) intuition.
 A: While in general one cannot expect density of Lipschitz mappings (as pointed out by Nik Weaver), the following classical result is in the positive direction. You can find a proof in Heinonen's book Lectures on analysis on metric spaces:

Theorem. If $f:X\to\mathbb{R}$ is a bounded and uniformly continuous function on a metric space, then there is a sequence of Lipschitz continuous functions $f_i:X\to\mathbb{R}$, $i=1,2,3,\dotsc$, such that $f_i\to f$ converges uniformly on $X$.

$X$ can be any metric space and compactness is not required. For that reason the argument based on the Stone–Weierstrass theorem mentioned in some comments cannot be applied here.
A: I claim that $X,Y$ are metric spaces with $X$ compact, and if $X$ or $Y$ is zero-dimensional, then every continuous function $f:X\rightarrow Y$ can be uniformly approximated by a locally constant function, and every locally constant function $f:X\rightarrow Y$ is Lipschitz.
Locally constant functions are Lipschitz
I claim that every locally constant function $f:X\rightarrow Y$ is Lipschitz whenever $X$ is compact. If $f:X\rightarrow Y$ is locally constant, then let $\mathcal{P}=\{f^{-1}[\{y\}]:y\in Y\}\setminus\{\emptyset\}$. Let $V=\bigcup_{C,D\in\mathcal{P},C\neq D}C\times D$. Then $V$ is compact, so
$d|_V:V\rightarrow\mathbb{R}$ has a minimum value $\delta$, and necessarily $\delta>0$, and the function $d$ has a maximum value $M$.
If $x,y\in X$ and $x,y$ belong to different blocks of $\mathcal{P}$, then $d(x,y)\geq\delta$ while $d(f(x),f(y))\leq M$, so $d(f(x),f(y))\leq d(x,y)\cdot\frac{M}{\delta}$ in this case. In fact, $d(f(x),f(y))\leq d(x,y)\cdot\frac{M}{\delta}$ whenever $x,y\in X$.
When $X$ is zero-dimensional.
Let $f:X\rightarrow Y$ be a continuous function. Let $\epsilon>0$. Then the cover $\{f^{-1}(B_\epsilon(y))|y\in Y\}$ has a refinement $\mathcal{P}$ which is a partition of $X$ into clopen sets. Now, for each $C\in\mathcal{P}$, let $y_C\in Y$ be an element with $C\subseteq f^{-1}(B_\epsilon(y_C))$. Then let $g:X\rightarrow Y$ be the function where $g[C]=\{y_C\}$ whenever $C\in\mathcal{P}$.
Then whenever $x\in C\in\mathcal{P}$, we have $g(x)=y_C$ while $f(x)\in B_\epsilon(y_C)$, so $d(f(x),g(x))<\epsilon$ while $g$ is locally constant.
when $Y$ is zero-dimensional
Suppose that $Y$ is zero-dimensional. Let $f:X\rightarrow Y$ be continuous. Then $f[Y]$ is compact. Therefore let $\epsilon>0$. Consider the cover
$\{f[Y]\cap B_{\epsilon/2}(y)\mid y\in Y\}$. Then there is a partition $\mathcal{P}$ of $f[Y]$ into sets that are clopen in $f[Y]$ but where $\mathcal{P}$ refined the cover $\{f[Y]\cap B_{\epsilon/2}(y)\mid y\in Y\}$. In particular, each set in $\mathcal{P}$ has diameter less than $\epsilon$.
For each $C\in\mathcal{P}$, let $y_C\in Y$, and let $g:X\rightarrow Y$ be the function where $g(x)=y_C$ whenever $f(x)\in C$. Then whenever
$f(x)\in C$, we have $g(x)=y_C\in C$ as well, so $d(f(x),g(y))<\epsilon$. Therefore, $g$ is a locally constant continuous function with $d(f,g)<\epsilon$.
A: Let $X$ be the unit circle and let $Y$ be the Koch snowflake, both with euclidean metric inherited from $\mathbb{R}^2$. There is a continuous homeomorphism from $X$ onto $Y$, but there is no nonconstant Lipschitz function from $X$ to $Y$, because the image of $X$ under any Lipschitz function is rectifiable.
A: Let $(X,\rho)$ be a compact metric space, and let $(Y,d)$ be a separable metric space. Then I claim that one can endow $X$ with a compatible metric $d$ such that every continuous $f:X\rightarrow Y$ can be uniformly approximated by a Lipschitz function.
Let $(f_n)_{n\geq 0}$ be a sequence of continuous functions such that every continuous $f:X\rightarrow Y$ can be uniformly approximated by some $f_n$. Let $(\alpha_n)_{n\geq 0}$ be a sequence of positive real numbers such that $\alpha_n\cdot\operatorname{Diam}(f_n[X])\rightarrow 0$. Then define a metric $d$ on $X$ by setting $$d(x,y)=\rho(x,y)+\sup_n\alpha_n\cdot d(f_n(x),f_n(y)).$$ Then the metric $d$ is compatible with the original topology on $X$. Furthermore, for each $n$, we have
$d(f_n(x),f_n(y))\leq\alpha_n^{-1}\cdot d(x,y)$, so each $f_n$ is Lipschitz.
