Then $f$ is constant (in particular, $f$ is differentiable).
To show this, consider $x\ne y$, split the interval between $x$ and $y$ into $n\geqslant1$ parts of length $|x-y|$ and apply the triangular inequality. This yields
$$
|f(x)-f(y)|\leqslant\sum_{k=1}^n\left|f\left(x+\frac{k-1}n(y-x)\right)-f\left(x+\frac{k}n(y-x)\right)\right|.
$$
Now, apply the hypothesis to each of these intervals. The result is
$$
|f(x)-f(y)|\leqslant\sum_{k=1}^n\frac{|y-x|^2}{n^2}=\frac1n|y-x|^2.
$$
When $n\to\infty$, this proves that $f(x)=f(y)$.
Note that the same result holds as soon as $|f(x)-f(y)|\leqslant C|x-y|^a$ for every $x$ and $y$, for some $a\gt1$.