Why don't X-rays/Gamma rays ionize all the atoms at the surface of a material? Recently I've been wondering why certain materials are transparent or opaque to different wavelengths of light. The most common explanation for why a material, like glass, is transparent (in the visible spectrum) is because the photons of those wavelengths don't have enough energy to excite electrons to a higher energy state, so the photons move through the material unaffected. Once you reach a critical frequency, however, the photons will begin to be absorbed because they have enough energy to excite the electrons (which is why glass is opaque in ultra-violet). By that logic, one would expect that ALL frequencies higher than the critical point would be opaque. That is not what happens, however, as x-rays/gamma-rays penetrate deeply into certain surfaces (like your skin).
Furthermore, x-rays/gamma-rays can ionize atoms by providing an electron with enough energy to escape the atom (which I believe is the cause of the photoelectric effect). Finally, an escaped electron can release some of its remaining energy through Compton Scattering, producing a lower frequency wave than that of the incident one.
Compton Scattering seems to offer a candidate solution; i.e. that it's the scattered, lower frequency waves that make it through. However, according to this article, and more specifically this graphic (shown below), Compton Scattering starts occurring at a certain energy threshold, so it doesn't explain the relatively high penetration depth of lower frequencies. Furthermore, the graph also demonstrates that the penetration depth is proportional to the photon's energy, which again contradicts the trend discussed in the first paragraph, where one would expect the penetration depth to decrease as the photon's energy increases.

I have looked for an answer on several sites, but none have provided me with a fully satisfying answer. These sites tend to either simplify the material, or simply gloss over this particular aspect of the more general question: "Why are materials transparent?". So, to summarize, my question is:
Why does the penetration depth of high frequency waves increase for higher energies, and why is this not (apparently) applicable to lower frequencies?
Given a high enough frequency, but still lower than the Compton Scattering frequency, why aren't all surface atoms ionized, effectively making the material opaque? (i.e. photoelectric absorption) 
 A: All photon absorptions happen "on the surface" of a material.  However the depth of "the surface" depends on the cross sections for the photon absorption processes involved.  For visible and UV photons these cross sections depend on the atomic structures and molecular structures and crystal structures in quite complicated ways.  For low-energy x-rays, you may have photon wavelengths comparable to the angstrom-scale spacing between atoms, which permits coherent scattering and diffraction.  Once the wavelength of the light becomes smaller that the spacing between atoms, the photon essentially interacts with each atom separately, and the probability that a photon travels a distance $\ell$ without scattering is given by $\exp(-n\ell\sigma)$, where $n$ is the number density of scatterers and $\sigma$ is the cross section.
For very high-energy photons, the mean free path between collisions in matter does in fact level off.  You just needed a bigger figure:

(This image is from the Particle Data Group.)  


*

*For sub-MeV photons the dominant contribution to photon scattering is electronic transitions in the atoms.  As the photons become energetic enough to knock out electrons from the next shell down, the mean free path suddenly decreases, which gives the curves their "spiky" shape (also present in your example).  

*For MeV-scale photons the dominant effect is Compton scattering, and so the most important parameter in the mean free path is the number of electrons that the photon passes.  This is why all the curves except H come together around 2 MeV: most materials have roughly one electron for every two nucleons, except hydrogen which has roughly one electron for every nucleon.

*For higher-energy photons the dominant scattering process is electron-positron pair creation, which occurs when the high-energy photon scatters off of "virtual photons" in the electric field between the atomic electrons and their nucleus.  The internal electric field is stronger for heavier nuclei, so a kilogram of heavy nuclei will stop more high-energy photons than a kilogram of lighter nuclei.
Note that while the mean free path between photon-material interactions levels off for photons somewhere above 100 MeV, the amount of material that's required to "stop" the photon continues to grow, more or less without any upper bound.  This is because the photon doesn't stop at its first interaction, but divides its momentum among the electron-positron pairs, scattered electrons, and lower-energy photons that it creates.  This "shower" of electromagnetic leftovers propagates forward in a cone, and can penetrate quite a bit of material.
A: I don't think there's any simple answer to your question that encompasses all materials. Scattering and absorption in matter has many contributions and isn't just Compton scattering. To begin with, particles that penetrate matter will generically scatter multiple times before being stopped and the cross-section will change when they get slower. The absorbtion of low frequencies depends on the shell structure of the atoms, on the geometry of the molecules and the symmetries of the lattice if you have a crystal. Not to mention that it depends on the type of particle that scatters. For the general question of penetration depth of light in matter, you might want to read up on the Beer–Lambert law.
A: You are thinking in terms of atoms and molecules and you are mainly talking of solid state matter .
Solid state is another quantum mechanical phase, it has lattice structure with much smaller energies than atomic and molecular transition structures. Lattices have vibrational levels which are mainly responsible for the black body radiation solids emit,  infrared is also photons.
A rule of thumb with radiation impinging on solids is that if the wavelength is smaller than the lattice dimensions the photons can penetrate easily the lattice, interacting only with direct scatters hence the higher penetration of X rays and gamma rays. Here is an article that discusses the penetration of radiation, X rays and higher.
For glass  and optical frequencies there is a good answer here in this site., essentially the structure of the transparent materials is such that the photons pass through without loosing energy in the visible.
For infrared where the wavelengths are large in comparison with lattices or distances between molecules in liquids, the photon can give up its energy in collective excitations at the surface gradually heating up the material. 
For ultraviolet,  glass, depending on the type, has some absorptive bands, the photon energy transferred at the surface to  collective modes or breaking molecular bonds and transformed to heat ( infrared) further in.
So your 

Once you reach a critical frequency, however, the photons will begin to be absorbed because they have enough energy to excite the electrons (which is why glass is opaque in ultra-violet). 

has small probability to happen until x-ray  energies are reached which are the energies of bound electrons, and the link above gives the dependence in a simplified manner.
