The X and Y position of the joystick are output as analog voltage on the output pins. In this joystick, a separate potentiometer is installed for both the X-axis and the Y-axis.
In the resting state, the potentiometer is in the middle, so the two potentiometers (X and Y-axis) and thus the applied voltage are identical. If, for example, the position of the X-axis is changed, the respective resistances change depending on the current position.
Depending on how the resistances are divided among themselves, this results in a corresponding voltage value that can be measured between the resistances, thus determining the position of the axis.