Short answer:
The top loop is effectively a battery with a variable voltage. When the circuit is in equilibrium at either step, and the current through $\text{G}$ is zero, we effectively have a simple circuit with one loop with two equal batteries facing in opposite directions, trying to drive the current in opposite directions, and neither wins with a net current of zero. A water analogy would be to have two equal pressure pumps drawing from the same reservoir with their discharges connected by a hose, so they are trying to drive a water current in opposite directions through the hose. Since there is equal pressure at both ends of the hose, there is no water flow in the hose.
Detailed description of the circuit:
Step 1
First, consider the top loop in isolation.
The total resistance of the top loop is $R_T = R_h + R_{\text{AB}}$ where $R_{\text{AB}}$ is the resistance of the length of the wire going from $\text{A}$ to $\text{B}$. Define the voltage of the left side of the circuit as zero so $V_{\text{A}} =0$, and the positive terminals on the left of all the cells are also zero.
The top loop with sliding contact $l_1$ is a voltage divider circuit, and the voltage at the sliding contact is given by $ \Delta V = R_{\text{A} l_1}/R_{T}$.
As the sliding contact is moved from $\text{A}$ to $\text{B}$, the voltage drops at the contact point.
When the voltage drops to the same voltage as the negative terminal of cell $\text{E}_1$, the voltage on either side of Galvanometer $\text{G}$ is equal, so there is no potential difference across $\text{G}$ and no current flow through $\text{G}$. At this point, we have:
$$V_{L_1} = \frac{ R_{\text{A} l_1}}{R_{T}} = V_{\text{E}_1} \implies \frac{ R_{\text{A} l_1}}{ V_{\text{E}_1}} = R_{T} \tag{1}\label{eq:1}.$$
Step 2
Now, cell $1$ is disconnected, and cell $2$ is connected to the circuit.
The slider is moved until there is no current through $\text{G}$, and this indicates that the voltage at the slider contact point is now equal to the voltage on the negative terminal of cell $\text{E}_2$.
We now have:
$$V_{L_2} = \frac{ R_{A l_2}}{R_{T}} = V_{\text{E}_2} \implies \frac{ R_{A l_2}}{ V_{\text{E}_2}} = R_{T} \tag{2}\label{eq:2}.$$
We can equate equations $\eqref{eq:1}$ and $\eqref{eq:2}$ and obtain:
$$\frac{ R_{\text{A} l_1}}{ V_{\text{E}_1}} = \frac{ R_{\text{A} l_2}}{ V_{\text{E}_2}}$$
$$ V_{\text{E}_2} = V_{\text{E}_1} \frac{ R_{\text{A} l_2}}{ R_{\text{A} l_1}} = V_{\text{E}_1} \frac{ l_2} {l_1}.$$
This allows us to determine the unknown voltage of $\text{E}_2$ knowing only the value of cell $\text{E}_1$ and the ratio of the lengths $l_1 $ and $l_2$.
The working principle of the circuit depends on the voltage at the slider contact being equal to the voltage of the connected cell so that there is no current flow through $\text{G}$ and, therefore, no current flow through the connected cell.
The voltage at the slider provides a counter-motive force to the connected cell and prevents any current from flowing through the connected cell because a current requires a voltage difference to drive it. When the circuits are balanced at both steps, the current in the top loop is the same at both stages, and the lower loop makes no difference to conditions in the top loop because there is no current flow in the lower loop (at equilibrium).