Atmospheric composition of exoplanets based on the thermal escape of gases and implications for habitability