One U.S. idiom that may apply here is "odd man out." According to Christine Ammer, American Heritage Dictionary of Idioms (1995), the phrase can be used in a gender-neutral sense:
odd man out 1. A person who is left out of a group for some reason, as in The invitation was for couples only, so Jane was odd man out. [Mid-1800s] 2. Something or someone who differs markedly from others in a group, as in Among all those ranch-style houses, their Victorian was odd man out. [Late 1800s]
The first definition here (with X and Z forming a group of two people) is the one relevant to the poster's example.
A longer phrase that might be applicable is to say that Y "lost out at musical chairs." Ammer gives this summary of the phrase "play musical chairs":
musical chairs, play Move around from position to position, such as the jobs in an organization. [Example omitted.] This expression alludes to the game in which children walk around a number of seats while music plays, and there is one less chair than players. When the music stops the players must sit down, and the player who is left standing is eliminated. Then another chair is removed, and the game goes on until only one player is left sitting. [c. 1900]
In the context of the poster's scenario, the shifting alliances among X,Y, and Z are the setting for a game of musical chairs with three players and only two chairs; when the music stops, X and Z grab the available seats and Y is left standing.