However, the host star can help the atmosphere escape. Sometimes the gravity of the host star pulls the atmosphere from the planet because it is stronger. More commonly, the intense heat from the star and energetic explosions called flares give so much energy to the particles in the planet’s atmosphere that they vibrate and move enough to overcome the planet’s gravity and escape. In this way, the atmosphere will lose its lightest constituents first, and astronomers can detect hydrogen streaming away. We have been able to measure this for some exoplanets, which look like giant comets, with a tail of gas streaming away from the direction of the planet’s orbit.
How the planets got to orbit so close to their stars in the first place is another question, and it is still a matter of scientific inquiry. The process that moved them so close to their stars is called migration; there are a number of theories as to what causes it. For example, another star could have come close to the system, pulling the planet and moving it inward. Or, while the planet was forming, other forming planets could have caused an imbalance, prompting the planets to move around until they settled and became stable.
The truth is, we are not sure yet what caused this to happen to more than 300 known exoplanets, spiraling them in to settle where we see them today. But the more we discover and learn about their atmospheres and environments, the more we can understand and perhaps work out why that did not happen in our own solar system — and whether that might be the reason I am here to answer your question!