Potential energy of a continuous mass distribution like liquid is the integral of $y \cdot dm \cdot g$. For a liquid column of uniform density in a cylindrical container, the center of mass is at half the height. The potential energy is proportional to the mass and the height of the center of mass. When the liquid redistributes to reach equilibrium in connected identical containers, the total volume is conserved, and the liquid levels become equal.