Assume that $a\sim b$ and $b\sim c$. Assume that $a\nsim c$. So there is a continuous function $f:X\to\mathbb{R}$ such that $f(a)=0$ and $f(c)=1$ but $f(x)\neq 1/2$. Now consider $X_1=f^{-1}(-\infty, 1/2)$ and $X_2=f^{-1}(1/2, \infty)$. These are both open, nonempty and their union is $X$.
Assume that $b\in X_1$ and consider
$$h:(-\infty, 1/2)\cup (1/2,\infty)\to (-\infty, 1/2)\cup (1/2,\infty)$$
$$h(x)=\begin{cases}
0 &\text{if }x\in(-\infty, 1/2) \\
x &\text{otherwise}
\end{cases}$$
Obviously $h$ is continuous. Now consider $g=i\circ h\circ f$ where $i:(-\infty, 1/2)\cup (1/2,\infty)\to\mathbb{R}$ is the inclusion. It follows that
$$g(b)=h(f(b))=0\text{ since }f(b)\in(-\infty, 1/2)$$
$$g(c)=h(f(c))=h(1)=1$$
But $g$ doesn't have $1/2$ in its image by the construction. So $b\nsim c$ which is a contradiction.
For case $b\in X_2$ you just switch $h$ to be $1$ on $(1/2,\infty)$ and identity otherwise. Then you consider $g(b)$ and $g(a)$.
Both cases lead to contradiction which completes the proof. $\Box$
P.S. It doesn't seem that the assumption about $X$ being compact Hausdorff is necessary?