Let $X$ be a compact metric space, and assume $f : X → X$ satisfies $$d(f(x), f(y))< d(x, y), \forall x \neq y ∈ X.$$ Define a function $g : X → \mathbb{R}$ by $g(x) = d(x,f(x)), \forall x ∈ X$. Prove the following statements.
a) $|g(x)-g(y)| \leq 2d(x,y), \forall x,y \in X$.
b) $g$ is continuous and $g(x)=0$ for some $x \in X$.
$\text{Proof:}$
a) Observe that \begin{align*}|g(x)-g(y)| &=|d(x,f(x))-d(y,f(y))| \\ &=|d(x,f(x))-d(f(x),y)+d(f(x),y)-d(y,f(y))| \\ &\leq |d(x,f(x)-d(f(x),y)|+|d(f(x),y)-d(y,f(y))| \\ &\leq d(x,y)+d(f(x),f(y)) \\ &\leq 2d(x,y), \end{align*} whre in the last step we used the hypothesis that $d(f(x), f(y))< d(x, y), \forall x \neq y ∈ X.$
b) To show continuity we take $\delta= \large\frac{\varepsilon}{2}$. Then if $d(x,y)< \delta$, we have by part a) that $|g(x)-g(y)|< \varepsilon$.
To show that there exists $x\in X$ such that $g(x)=0$, we follow AlexL's answer and note that since $g$ is continuous and $X$ is compact, $g$ attains its minimum at some $x \in X$. Suppose that for that for $g(x)\neq 0$, and so $f(x)\neq x$. Then $$g(f(x))=d(f(x),f(f(x)))<d(x,f(x))=g(x),$$ which is a contraction to $g$ attaining its minimum at $x$. It follows that $g(x)=0$, and this completes the proof.
Since $X$ is compact and $g$ continuous, there exists $x_0 \in X$ such that $g(x_0)$ is minimal. I let you show that we must have $g(x_0)=0$.