I've heard this claim many times, that when the derivative of a function is $0$ everywhere in its domain, then that function is a constant function.
But what about functions like the following two:
$$f : (4,6)\cup (6,7) \to \mathbb{R}$$
$$f(x) = \begin{cases} 2, \, x \in (4,6) \\ \\ 7, \, x \in (6,7) \end{cases} $$
Here, $ f'(x) = 0, \, \forall x \in D_f$, where $D_f$ stands for domain of $f$.
I'm writing this after I read the proof of something similar to it in this question here:
If the derivative of a function is zero, is the function a constant function?
When the derivative is zero everywhere in an open set $S$, the function is locally constant in $S$. If the set $S$ is connected, that implies the function is constant. If the set is not connected, then there are examples of locally constant functions that are not constant.
What is additionally confusing is that the "domain of a function", i.e. the set where it is defined, may not be a "domain", which means an open and connected set. On "domains", derivative zero means the function is constant.