After the first transfer, the first vessel contains $x-z$ gallons of wine and $z$ gallons of water; the second contains $z$ gallons of wine and $y-z$ gallons of water.
The second transfer takes $z$ gallons of the first mixture and adds it to the second, and vice versa. We can write the resulting amount of wine in the first vessel as: $$ \frac{x-z}{x} (x-z) + \frac{z}{y}(z) $$ where the first term is the wine left from after the first transfer, and the second term is the new wine from the second transfer. From the problem, we may write: $$ \frac{x-z}{x} (x-z) + \frac{z}{y}(z) = x-z $$ From which we just need a bit of manipulation to produce: $$ \begin{align*} (x-z)^2 y + z^2x &= (x-z)xy \\\ x^2y - 2xyz + yz^2 + xz^2 &= x^2y - xyz \\\ yz^2 + xz^2 &= xyz \\\ (x+y)(z)(z) &= (xy)z \end{align*} $$ Which, assuming $z \
eq 0$, gives you the desired equality.