The first thing to bear in mind, is that Y and X also have a resistance.The Voltage is split between the resistor R1 and the parallel system of R2, Y and X.
Within the parallel system, the voltage is common between the two branches, but split across R2 and Y. So, the voltage across R2 plus the voltage across Y is equal to the voltage across X. And this voltage (across X) plus the voltage across R1 is equal to the voltage of the battery (24V)