If $|f(x)-f(y)|\le(x-y)^2$ for all $x,y\in\mathbb R$, then it's easy to show that $f'=0$ everywhere, and the mean value theorem implies that that means $f$ is constant. If there were a gap in the real line and $f=3$ on one side of the gap and $f=4$ on the other side of the gap, then $f'=0$ everywhere but $f$ is not constant. Gaplessness enters via the mean value theorem.
But I wonder if the proposition holds even in a line with gaps. For example if $f:\mathbb Q\to\mathbb Q$ and for all $x,y\in\mathbb Q$ this inequality holds, does that imply $f$ is constant? And what about other gap-filled lines than $\mathbb Q$? Such as $\mathbb R\setminus A$ where $A$ is a finite set, or a countable set, or a set whose complement is dense, or whatever set it might be of interest to ask this question about?