This question already has an answer here:
Let $(X, d)$ be a compact metric space. Let $f: X \to X$ be such that $d(f(x), f(y)) = d(x, y)$ for all $x, y \in X$. To show that $f$ is onto.
Since the function $f$ satisfies $d(f(x), f(y)) = d(x, y)$ for all $x, y \in X$ we can say that the function is uniformly continuous.
Now let us assume that $f$ is not onto then $f(X) \subset X$, a proper subset. Then how can I bring a contraction to show that $f$ will be onto??