Question: Let $(X,d)$ be a compact metric space and let $f:X\to X$ be a map such that $d(f(x),f(y))\geq d(x,y)$ for all $x,y\in X$. Show that $f$ is an isometry onto $X$.
Solution: First we will see that $f$ is an isometry, then that $f$ is onto $X$.
1. Given a (small) $r>0$, let $K_n(r)$ be the set of $n$-tuples $(x_1,...,x_n)$ in $X^n$ such that $d(x_i,x_j) \ge r$ for every $i \ne j$. By compactness of $X$, there is$^*$ (see footnote) a maximal $n$ such that $K_n(r) \ne \emptyset$. We now fix $n$ to take this value. Since $K_n(r)$ is a closed subset of $X^n$, it is compact, so the continuous function
$$g(x_1,\ldots x_n):= \sum_{i >j} d(x_i,x_j)$$ attains its maximum over $K_n(r)$ at some n-tuple $(x_1^*,\ldots ,x_n^*) \in K_n(r)$.
Write $y_i=f(x_i^*)$ for each $i$, and observe that $(y_1,\ldots,y_n) \in K_n(r)$ and $g(y_1,\ldots,y_n) =g(x_1^*,\ldots ,x_n^*)$; thus we must have $d(y_i,y_j)=d(x_i^*,x_j^*)$ for all $i,j$.
Given $z,w \in X$, maximality of $n$ ensures that there is $i\le n$ such that $d(y_i,f(z)) \le r$, so $d(x_i^*,z) \le r$. Similarly, there is $j \le n$ such that $d(y_j,f(w)) \le r$, so $d(x_j^*,w) \le r$. We conclude that
$$d(f(z),f(w)) \le d(f(z),y_i)+d(y_i,y_j)+d(y_j,f(w)\le d(x_i^*,x_j^*) +2r $$ $$ \le d(x_i^*,z)+d(z,w)+d(w,x_j^*)+2r \le d(z,w) +4r\,.$$
Since $r>0$ can be arbitrary,
$$\forall z,w \in X, \quad d(f(z),f(w)) \le d(z,w) \,.$$
2. If $f$ was not surjective, then $f(X)$ is a closed subset of $X$ and there must exist some $u \in X$ and $r>0$ such that $d(u,f(X))>r$. Using the notation of part 1, we consider the same $n$, and the $n$-tuples $(x_1^*,\ldots ,x_n^*) \in K_n(r) $ and $(y_1,...y_n) \in K_n(r)$. Then $(u,y_1,\ldots,y_n) \in K_{n+1}(r)$, contradictng the maximality of $n$.
$(*)$ Footnote: By compactness of $X$, it can be covered by finitely many open balls of radius $r/2$, call them $\{B(v_i,r/2)\}_{i=1}^M$. If $(x_1,\ldots x_n) \in K_n(r)$, then each ball $B(v_i,r/2)$ can contain at most one $x_j$, so $n \le M$.