Claim: Given a function $f:K \to K$ which does not increase distances on a compact metric space $(K,d)$, surjectivity is equivalent to preserving distances.
Proof: (a) First suppose $f$ preserves distances but is not surjective,
so there exists $z_0 \in K \setminus f(K)$. Let $K_0=K$. Since $K_1:=f(K)$ is compact, we have
$$\delta:=d(z_0,K_1)>0 \,.$$
For $n \ge 1$, define inductively $K_n=f(K_{n-1})$ and $z_n=f(z_{n-1}) \in K_n$. Then $d(z_{n-1},K_n)=\delta$ for all $n \ge 1$, and for positive integers $\ell<n$ we have $z_n \in K_{\ell+1}$, so
$$ d(z_\ell,z_n) \ge \delta \,.$$
Thus the sequence $\{z_n\}$ does not have a convergent subsequence, contradicting compactness.
(b) Suppose that $f$ is surjective, and $x_0,y_0 \in K$ are distinct.
Given $\epsilon>0$, there is a finite set $S \subset K$ such that
$\cup_{s \in S} B(s,\epsilon) =K$, where $B(s,\epsilon)$ is the open ball of radius $\epsilon$ centered at $s$. For $n \ge 1$, define inductively
preimages $x_n,y_n$ such that $f(x_n)=x_{n-1}$ and $f(y_n)=y_{n-1}$.
For each $n$, there exist $\tilde{x}_n, \tilde{y}_n \in S$ such that
$d(\tilde{x}_n,x_n)<\epsilon$ and $d(\tilde{y}_n,y_n)<\epsilon$.
In the infinite sequence $\{(\tilde{x}_n, \tilde{y}_n) \}_{n \ge 1}$,
some element of the finite set $ S \times S$ must repeat.
Thus there exist $\ell>k>0$ such that
$ (\tilde{x}_k, \tilde{y}_k)=(\tilde{x}_\ell, \tilde{y}_\ell) \,,$
so
$$d(x_k,x_\ell)<2\epsilon \quad \mbox{ and} \quad d(y_k,y_\ell)<2\epsilon \,. $$
Applying $f^{k+1}$, we infer that
$$d(f(x_0),x_{\ell-k-1})<2\epsilon \quad \mbox{ and} \quad d(f(y_0),y_{\ell-k-1})<2\epsilon \,. $$
Therefore, by the triangle inequality,
$$d(x_{\ell-k-1}, y_{\ell-k-1}) < d(f(x_0),f(y_0))+4\epsilon \,.$$
Applying $f^{\ell-k-1}$ yields that
$$d(x_{0}, y_{0}) < d(f(x_0),f(y_0))+4\epsilon \,.$$
Since $\epsilon>0$ was arbitrary, this proves that
$$d(x_{0}, y_{0}) = d(f(x_0),f(y_0)) \,,$$
so $f$ is distance preserving.
Edit: According to [1], The equivalence in the claim is due to [2].
[1] Hu, Thakyin, and W. A. Kirk. "On local isometries and isometries in metric spaces." In Colloquium Mathematicum, vol. 44, no. 1, pp. 53-57. Institute of Mathematics Polish Academy of Sciences, 1981.
[2] Freudenthal, Hans, and Witold Hurewicz. "Dehnungen, verkürzungen, isometrien." Fundamenta Mathematicae 26, no. 1 (1936): 120-122.