This can be explained by fundamental principles of Light-Matter Interaction and Absorption & Emission of Radiation.
The electrons/atoms inside any conducting volume boundary oscillate due to thermal motion/heat energy. These vibrations can cause the electrons in the atoms to move slightly from their normal positions, giving rise to electric dipole moments which generates electro-magnetic standing waves inside that cavity.
From the Coulomb’s force law between two electric charges and Ampere’s force law (force per unit length) of magnetic induction, we can find the energy of a standing-wave electromagnetic field and the spectral energy density
The standing waves satisfying the boundary conditions as a function of frequency with each wave having an energy can be explained bythe spectral distribution of energy density by Rayleigh-Jeans black-body energy density distribution and Planck black-body energy density distribution.
How to generate radiation?
The energy flow between the atoms in the cavity (e.g. a two-level atom) and the field modes of the cavity are described by Einstein rate equations (also Einstein A and B coefficients) that determines the resonant stimulated absorption and emission, E2−E1 = hω_0, with the rates proportional to the spectral energy density ρ_ω of the cavity modes.
and eventually wavelength of electromagnetic radiation emitted by an atom.
To generate the radiation, you've to excite the atoms to higher energy level through an external pump as in any laser or resonator cavity.
Moreover, the emission of electromagnetic radiation is not limited to infrared radiation. Atoms can emit EM radiation across the entire electromagnetic spectrum, depending on the energy of the transition and the energy difference between the two energy levels involved.
For example ASML uses CO2 laser on molten tin to extract extreme Ultra Voilet radiation that is ground-breaking and no other company has ever been able to do that.
In the end, i noticed that some people used chatgpt to answer your question, please demotivate them as it doesn't have some logical reasoning for now.
Reference & Further Reading
Read this book
https://www.ifsc.usp.br/~strontium/Teaching/Material2011-2%20SFI5877%20Luzmateria/Weiner%20Light&matter.pdf
• A thorough discussion of the theory of absorption and emission of radiation
from multilevel (real) atoms can be found in
Sobelman, I. I., Atomic Spectra and Radiative Transitions, Springer Verlag, Berlin (1977)
• A comprehensive discussion of absorption and emission in real atoms, gas-phase laser action, and atomic spectroscopy with laser sources can be found in
Corney, A. Atomic and Laser Spectroscopy, Clarendon Press, Oxford (1977)
• Early history of the quantum theory and the problem of black-body radiation
may be found in
J. C. Slater, Quantum Theory of Atomic Structure vol. I, chapter 1,
McGraw-Hill, New York, 1960