Your statement is true if you correct it slightly:
A topological space $ X$ is connected if any continuous map from $X$ to any two-point discrete set is constant.
Proof.
I use the definition of a connected topological space given in [1]:
A topological space $X$ is connected if there does not exist a continuous map from $X$ onto a two-point discrete space.
Denote this two-point discrete space by $\{0, 1\}$. Then we can rewrite the above statement more mathematically as:
$X$ connected if:
$\neg (\exists f: X \rightarrow \{0, 1\}, f$ continuous and surjective$)$
This is equivalent to:
$$ \forall f: X \rightarrow \{0, 1\} \text{ continuous}, f \text{ not surjective}$$
$\iff$
$$ \forall f: X \rightarrow \{0, 1\} \text{ continuous}, f(X) = \{0\} \text{ or } f(X) = \{1\}$$
i.e., $ f$ is constant, as required. $\square$
References
[1] Definition 12.1 page 114 of "Introduction to Metric & Topological Spaces", Second Edition, by Wilson A. Sutherland