If the energy density becomes high enough electron-positron pairs will form. This limits the energy density of a photon gas. For example pairs can form in strong laser fields by multiphoton processes. It does not in principle require single photon energies of order $mc^2$. The so-called strong field Breit-Wheeler process happens of course at an energy scale much lower than that required for black hole formation.
https://www.sciencedirect.com/science/article/pii/S2468080X17300183