Solution (source code)

= Solution

This is always true: it is the <Heine-Cantor theorem>. If uniform continuity failed, there would be an $\varepsilon>0$ and sequences $x_n,y_n\in X$ such that
$$
d_X(x_n,y_n)<\frac1n,
\qquad
d_Y(f(x_n),f(y_n))\geq\varepsilon.
$$
By <sequential compactness of a compact metric space>, some subsequence $x_{n_k}$ converges to $x\in X$. The triangle inequality gives $y_{n_k}\to x$. Continuity then makes both image subsequences converge to $f(x)$, contradicting their separation by $\varepsilon$.