The hotter they get, the faster they move. If they are moving fast enough, they can reach escape velocity , the point at which they have enough momentum to escape from the planet's gravitational field altogether. If they are moving away from the planet, they can disappear into space. As the molecules leave, the planet's atmosphere becomes just a tiny bit less. Over a long period of time, the atmosphere can slowly drift away.
Atoms are especially liable to leave a small planet or moon.
Small, low mass moons and planets have low gravity to begin with, so the atoms are not held to the surface very strongly. Heat makes matters worse. Mercury is a small planet, close to the sun. It has a day time high temperature of 350 degrees Centigrade, which would make the atmospheric atoms move rapidly. In addition, particles from the sun, the solar wind collide with the atmospheric atoms, speeding them up further and perhaps changing their direction of movement.