Locally Constant Functions on Connected Spaces are Constant
Solution 1:
Let $\mathcal{S}$ be the set of open sets in the domain such that $f$ is constant on the open set.
Since $f$ is locally constant, we know that every $x\in \mathrm{dom}\, f$ is a member of some $S\in \mathcal{S}$.
Now, pick $x_0$, and define two sets: $U = \{x: f(x)=f(x_0)\}$ and $V=\{x: f(x)\neq f(x_0)\}$.
We can see that $U$ and $V$ are disjoint, and $U \cup V = \operatorname{dom} f$.
But each of $U$ and $V$ is just a union of open sets, namely sets in $\mathcal{S}$.
So $U$ and $V$ are both open.
Solution 2:
A variation and expansion of some of the ideas here:
In my first course on topology we were taught a following useful "chain-characterisation" of connectedness. Some definitions first: if $\mathcal{U}$ is a cover of a space $X$, then a chain in $\mathcal{U}$ is a finite indexed set $U_1,\ldots U_n \in \mathcal{U}$ such that for all $i=1,\ldots n-1$ we have that $U_i \cap U_{i+1} \neq \emptyset$, and it is called a chain from $x$ to $y$ in $\mathcal{U}$ (both points from $X$) when we additonally have $x \in U_1$ and $y \in U_n$.
Now:
A space $X$ is connected iff for every open cover $\mathcal{U}$ of $X$ we have a chain in $\mathcal{U}$ between any pair of points of $X$.
The chain-condition implies connectedness, because if $X$ is non-connected, we have decomposition of $X$ into 2 non-empty disjoint open sets $U$ and $V$, and then for $x \in U$ and $y \in V$ there can be no chain from $x$ to $y$ in the cover $\mathcal{U} = \{U, V\}$.
The reverse implication is a variant of the proofs in other replies: let $\mathcal{U}$ be any open cover of $X$ and fix $x \in X$. Then define $O$ to be the set of all $y \in X$ such that there is a chain from $x$ to $y$ from $\mathcal{U}$.
$O$ is non-empty, as any $x$ in $X$ is covered by some $U \in \mathcal{U}$ and then $U_1 = U$ is a chain from $x$ to $x$, so $x$ is in $O$.
$O$ is open: let $y$ be in $O$ and let $x \in U_1,\ldots U_n$ be a witnessing chain (from $\mathcal{U}$) for it. Then for every $z$ in $U_n$, that same chain will witness that $z$ is in $O$ as well, and so $U_n \subset O$, and every point of $O$ is an interior point. Note that we do not even need the cover to be open, just that the interiors cover $X$.
$O$ is closed: suppose that $y$ is not in $O$, and let $U$ be an element from $\mathcal{U}$ that covers $y$. Suppose that some $z$ in $U$ is in $O$, and again let $x \in U_1,\ldots U_n$ be a witnessing chain for it, so with $z \in U_n$. But then the chain $x \in U_1,\ldots U_n,U_{n+1} = U$ is a chain from $\mathcal{U}$ as well, because all intersections are non-empty in the beginning by assumption, and $U_n \cap U_{n+1}$ is non-empty, as both contain $z$, and this would witness that we have a chain from $\mathcal{U}$ from $x$ to $y$. But then $y$ would be in $O$, contrary to what we assumed. So $U$ misses $O$ entirely so $O$ is closed.
But now the connectedness of $X$ forces $O = X$ (there is only one non-empty clopen set) and then we have what we wanted in the chain condition, as $x$ was arbitrary.
Having this at our disposal we are almost done: let $f$ be locally constant and for every $x$ pick a neighbourhood $U_x$ such that $f$ is constant on $U_x$. We of course consider the cover $\mathcal{U} = \{U_x : x \in X \}$, and fix $x$ in $X$. If $y$ is another point in $X$ then we have a chain from $\mathcal{U}$ from $x$ to $y$ but when 2 sets from $\mathcal{U}$ intersect, it means $f$ is constant on their union. It follows that $f(x) = f(y)$ as required.
Other applications: in a locally compact (in the sense of every point has a compact neighbourhood) connected space for every $2$ points there is a compact subset of $X$ that contains them both. Or a locally path-connected and connected space is path-connected (use path-connected open neighbourhoods, get a chain from $x$ to $y$, a glue together paths from $x$ to a point in the intersection of $U_1 \cap U_2$, a point in $U_2 \cap U_3$ etc to $y$.) and so on. It allows for all sort of local properties to get expanded more globally for connected spaces.