When a speck of comet debris strikes the Moon it vaporizes on impact, creating a shock wave in the lunar soil. For a sufficiently large impactor, this shock wave can breach the soil's dry upper layer and release water molecules from a hydrated layer below.
Source: NASA