Why do X-ray telescopes have to be in space? I have read this question:

For x-rays the (HUP limit) Δx becomes smaller than the distances between the lattice distances of atoms and molecules, and the photon will interact only if it meets them on its path, because most of the volume is empty of targets for the x-ray wavelengths of the photon.

Why do X-rays go through things?
As far as I understand, X-rays are one of the most penetrating electromagnetic radiation. They should easily penetrate Earth's atmosphere just like visible light. Then why do all x-ray telescopes have to be in space?

The image is from the DK Smithsonian Encyclopedia.
The only thing I found about this says something about atmospheric absorption, but does not go into detail, why x-rays get absorbed more then any other wavelength (like visible).
So basically I am asking why are x-rays one of the most penetrating in solids, but one of the least penetrating in gases?
 A: To extend very slightly upon BowlofRed's answer: X-ray photons interact with electrons. More electrons in an atom means more interactions, and more interactions means less penetration. In general terms, this means that the heavier the atom, the more electrons it has and the harder it is for an x-ray photon to pass through a solid chunk of it without getting scattered or absorbed. That's why lead is so effective as a shield against X-rays.
To make a good shield against X-rays out of atoms with fewer electrons in them, you just use a thicker layer of them to get the job done. In this regard, a column of air that is ~50 miles deep is just as good as a nice thick slab of solid lead.
A: Is water transparent? It seems so in a glass, but a kilometer of water is nearly opaque. The deep ocean is dark. Air at atmospheric pressure is similarly opaque to x-rays on a kilometer scale. It's even more opaque for long-wavelength "soft" x-rays, where you may be troubled by its opacity on a lab bench.
But for short-wavelength "hard" x-rays, you don't have to go all the way to space. If your telescope is above 99% of the atmosphere, in the upper stratosphere, it'll be able to function. In the early days of x-ray astronomy, we did much of the work from stratospheric balloons.
A: For typical X-rays of 20 keV, I found a density attenuation coefficient of 0.0757 m²/kg in air. Considering a typical air density of 1.2 kg/m³, this gives an attenuation coefficient of 0.09 m⁻¹. The inverse of that - around 11 meters - gives you the distance, after which an X-ray beam of 20 keV is attenuated to e⁻¹ of its original intensity. Taking 100 times that distance - 1.1 kilometers - results in an attenuation to e⁻¹⁰⁰. That's a number, that starts with zero and has over 40 more zeros after the decimal dot, before another digit comes. So it is safe to say, that the atmosphere is fully intranspartent to 20 keV photons.
At 100 keV, the density attenuation coefficient of air reduces to 0.0155 m²/kg. Therefore, the average length for an 1/e attenuation increases to around 50 meters. That's still not enough to "see" those hard X-rays / soft gamma rays through the atmosphere.
At 10 MeV, the coefficient further reduces to 0.00205, which gives an 1/e distance of around 400 meters. So, again, virtually all of those gamma rays are absorbed by the dense atmosphere between ground level and 3000 meters height. 11 km above ground, the typical flight head of aircrafts, the air density is reduced to 0.36391 kg/m³, resulting in an 1/e attenuation for a 10 MeV beam of 1340 meters. That gives you a tiny change to be hit by 10 MeV gamma quants, that are traveling towards earth from outer space, or which are generated from particles of the solar wind, that hit outer atmosphere at 25 km altitude and up.
On the legendary Concorde - 18 km flight height and surrounding air density of just 0.1 kg/m³ - the 1/e length further increases to almost 5 kilometers. As air also quickly thins out at higher altitude, those 10 MeV quants coming from above and directly heading down have a high probability to reach the Concorde and its passengers. The good news: Being so energetic, most of those 10 MeV quants will just hit through and not deposit much energy on the aircraft and its passengers.
Particles of TeV energy are strong enough to penetrate atmosphere and hit the ground. But as those particles are rare, direct hits to counters on the surface are very rare, too. But as they penetrate through atmosphere, they constantly deposit energy, namely through Czerenkov radiation, and that energy can be measured at nighttime. This makes the earth's atmosphere basically one huge Czerenkov counter for cosmic TeV particles.
Good reading starts are here:
https://arxiv.org/abs/astro-ph/0701766
https://www.hawc-observatory.org/science/detection.php
So, yes, SOME cosmic radiation can be detected through the atmosphere at ground level. But for X-rays and low- to medium-energy Gamma rays, the atmosphere is intransparent, and one has to go to space (or to very high flying balloons) to measure them.
A: X-ray (and gamma rays) are quite penetrating.  They can pass through solid matter with much less attenuation than visible light as an example.
But that doesn't mean that the attenuation is zero.  Put enough "stuff" in the way, and the energy is eventually scattered or absorbed.  In the case of the atmosphere, it's "just" air, but there is quite a bit of it.  The depth of the atmosphere is plenty to stop almost all UV/X/gamma radiation.
In fact most types of EM radiation are blocked by the atmosphere.  But our eyes see only the transparency in visible light.
The small molecules that make up most of the atmosphere ($N_2$, $O_2$, $Ar$) take a lot of energy to excite.  It turns out that visible light is just shy of the energy to do this efficiently, so interactions are very rare.  More energetic forms (including X-rays) can ionize these molecules, absorbing or scattering the radiation.  Given a thick enough layer, almost all the incoming radiation is removed.
A: Space is largely a vacuum. So atmosphere distortion of em spectrum is mitigated
X rays are hard enough to penetrate significant atmosphere but not perfectly. Earth's traces atmospheric gasses absorb Xrays...
