Yarns and/or fabrics are not fixed materials. They consist of separate fibres that will stretch when exposed to tension, i.e. they elongate during the process of being made into cloth (during spinning, weaving, bleaching, dyeing and the various finishing processes, yarns and cloth are under continuous tension). Some or all of this stretch within the fabric is retained in the post-loom fabric because of friction between the fibres and the yarns.
The stretch that occurs can be eliminated when the friction within the fabric is reduced. This will happen during soaking and/or washing, where both water and soap act as lubricants. The lubricants, along with the mechanical action of the washer, help the fibres relax and contract (shrink) back to their original length.
One of the reasons that dry cleaning does not shrink natural fabrics is that the friction within the fabric is not reduced by dampening.