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$.