Let 𝑋 be a topological space and 𝑥,𝑦∈𝑋.
If 𝑥 is (path-)connected to 𝑦 and 𝑦 is (path-)connected to 𝑧,
then 𝑥 is (path-)connected to 𝑧. #m/thm/topology
Hence both forms of connectedness form an equivalence relation.
For plain connectedness
Let 𝑥∼′𝑦 and 𝑦∼′𝑧,
i.e. there exists connected subspaces 𝑈1∋𝑥,𝑦 and 𝑈2∋𝑦,𝑧.
We claim that 𝑉=𝑈1∪𝑈2 is a connected subspace of 𝑋.
Let 𝜄𝑘:𝑈𝑘→𝑉 denote that natural inclusions of 𝑈𝑘 in 𝑉,
and 𝑓:𝑉→{0,1} be a continuous function.
Since 𝑓 and 𝜄𝑘 are continuous, so too are 𝑓𝜄𝑘:𝑈𝑘→{0,1}.
Thus 𝑓𝑤=𝑓𝑦 for all 𝑤∈𝑈1∪𝑈2=𝑉.
Hence 𝑓 is constant for 𝑉.
Therefore 𝑥∼′𝑧.
For path connectedness
Let 𝑓 be a continuous path from 𝑥 to 𝑦 and 𝑔 be a continuous path from 𝑦 to 𝑧.
Then the product 𝑓⋅𝑔 is a continuous path from 𝑥 to 𝑧.
Hence 𝑥∼𝑦∧𝑦∼𝑧⟹𝑥∼𝑧.