The Jovian planets formed well before the terrestrial planets in the formation of the solar system. They had more time to gather their mass and they had more material from which to form their planet. The result are extremely large and widely spaced planets. Escape speed is the velocity an object need to have in order to escape a certain gravitational field. Molecules and atoms of an atmosphere have a velocity that depends on their mass and temperature.
Heavier elements have a slower speed than lighter elements.
Hotter gas has a higher velocity than cooler gas of the same composition. The direction of these velocities are random. If the velocities of certain elements are greater than the Moon's escape velocity, then that element will eventually escape from the Lunar surface, once the velocity direction is upwards from the surface.