Suppose that $f(X) = A \cup B$ is a separation.
It is assumed here that $f(X)$ is not connected so that we can reach some contradiction.
Let $C = f^{-1}(A), D = f^{-1}(B)$. Then $C,D \neq \varnothing, C \cap D = \varnothing$. $\tag{1}$
This comes from the assumption that $A\cup B$ is a separation. [Added:]Note also that in this step, we also have
$$
X=C\cup D.
$$
Thus if we can prove that both $C$ and $D$ are open (in $X$), then we will have a desired contradiction.
Write $A = f(X) \cap U$, where $U \subset Y$ is open. Then $C = f^{-1}(A)=f^{-1}(U)$ is open since $f$ is continuous. Similarly, $D$ is open.
In this step, we are trying to argue that both $C$ and $D$ are open. Thus this fact (both $C$ and $D$ being open) and (1) together imply that $X$ is not connected, which is a desired contradiction.
[Added:] The reason we can write $A$ as the proof puts is that $A$ is assumed to be open in $f(X)$ with the subspace topology.
Let $P$ be that "$f:X\to Y$ is a continuous map between two topological spaces $X$ and $Y$". Let $Q$ be that "$X$ is a connected topological space". Let $R$ be that $f(X)$ is connected. So you statement is
$P$ and $Q$ implies $R$. (Or, if P and Q, then R.)
What we are trying to do in the proof in your question is that assuming $R$ is not true and $P$ is true, prove that $Q$ is not true.
The difference between the Contrapositive method and the Contradiction method is subtle. Let's examine how the two methods work when trying to prove "If P, Then Q".
- Method of Contradiction: Assume P and Not Q and prove some sort of contradiction.
- Method of Contrapositive: Assume Not Q and prove Not P.
The method of Contrapositive has the advantage that your goal is clear: Prove Not P. In the method of Contradiction, your goal is to prove a contradiction, but it is not always clear what the contradiction is going to be at the start.
See more for this in the question
Proof by contradiction vs Prove the contrapositive.