Does the real line have gaps? That's the issue. Suppose you can partition the line into two sets $A$ and $B$, so that
- Every real number belongs to either $A$ or $B$;
- No number belongs to both;
- Every member of $A$ is less than every member of $B$;
- For every member of $A$, there is a larger number that is still a member of $A$;
- For every member of $B$, there is a smaller number that is still a member of $B$.
In that case, there would be no boundary point, such that every number less than that point is in $A$ and every number greater than that is in $B$. That would be a gap.
Now suppose $f(x) = 0$ if $x\in A$ and $f(x)=1$ if $x\in B$. Then $f\;'(x)=0$ for every value of $x$, but $f$ is not constant.
You can't prove every function whose derivative is everywhere $0$ is constant unless you rule out gaps. The proof of the mean value theorem conventionally relies on Rolle's theorem, which in turn relies on the fact that a continuous function on a closed interval has a maximum and a minimum in that interval. That theorem is not true unless the real line is gapless. A continuous function could increase on the set $A$ described above and decrease on $B$, and it would have no maximum.
The mean value theorem is how the gaplessness of the line gets involved in the proof that if $f\;'=0$ everywhere then $f$ is constant.
Probably you could find other ways of proving that, but they'd have to invoke gaplessness somehow.