In the Statistical Mechanics book of Kerson Huang, it is written that "The isotherm in the $p$-$V$ diagram is horizontal during the phase transition, because the gas phase has a smaller density than the liquid phase." I couldn't understand this statement with mathematical equation, can anybody please explain this to me with relevant physical laws?
I can see why this quote would tend to cause confusion. I would have written, "The isotherm in the P–V diagram is horizontal during the phase transition because the two phases have different densities".
In other words, the horizontal segment arises not because of any particular aspect of the gas phase but simply because at constant temperature and pressure, the volume must change during the phase transition.
In contrast, there isn't a horizontal segment at the critical point because at this point, the two phases don't have different densities.
The reason the isotherms in the $P-V$ diagram must be horizontal for all volumes between the volumes of the two coexisting phases is a direct consequence of the condition of coexistence at the equilibrium of two phases with a different (molar) volume (or densities). In principle, one could think of a system where the density would jump from one value to another without allowing intermediate values. Or, like in the case of the van der Waals equation of state, or experimentally, in the case of metastable systems, there could be a continuous variation of the pressure without a horizontal part, even if the coexisting phases have different densities.
The special property controlling the existence of the horizontal part of the isotherm is that for every volume or density intermediate between the two extreme pure phase values, the system spontaneously organizes itself into phase-separated regions, and such regions are at the thermodynamic equilibrium, implying that they must have the same pressure.
Therefore, the real reason for the horizontal isotherm is not only the difference in densities but also the requirement of thermodynamic equilibrium in the inhomogeneous system corresponding to intermediate values of the volume.
I will add this to the answers that have been given already: In phase equilibrium we have the equality of temperature, pressure, and chemical potential of species across all phases present. When we plot an intensive property on the vertical axis (usually $P$ or $T$) and an extensive property on the horizontal axis (for example $V$ in the $PV$ graph or $S$ on the $TS$ graph, a tie line is always a horizontal straight line.
If we plot two extensive properties against each other (both expressed per unit mass), for example enthalpy versus entropy (Mollier chart), tie lines are straight but not horizontal.
In both cases the reason is that (i) each phase generally has its own value of the extensive property, and (ii) the extensive property of a two-phase mixture is the average of the value in each phase (the so-called "lever rule"). The exception is the critical point, where both phases have the same extensive properties and the tie line in this case collapses to a point.