Isn't there an absurd aspect to applying the equipartition theorem for this problem? Since there are an infinite number of electromagnetic wave frequencies permitted by the cavity length, and if each has an average energy of KT, then that would imply the total energy is infinite. This is very different than a gas with a finite number of particles, and thus finite energy.
The result is clearly absurd. No one ever doubted this! The question is, what is wrong with the argument? Classically those modes are there. So, why aren't they excited? If this seems like a trivial detail to you, well, it also seemed like a detail to people as esteemed as Lord Kelvin at the time, but in fact the resolution to this problem was to replace the entire edifice of classical mechanics dating back to Newton and Galileo with quantum mechanics!
Why was the equipartition theorem believed to be applicable to electromagnetic radiation? I know that classically the energy of a wave is proportional to the amplitude squared. But the electromagnetic radiation doesn't have mass with classical kinetic energy, and so I am wondering how one attempts to rationalize applying a concept for oscillating masses to an oscillating field. I do recognize that the radiation should be in some sort of equilibrium with the oscillating charges of the black body. I also see that if all of the kinetic energy of the vibrating mass was radiated away, then the electromagnetic wave would "acquire" all of this kinetic energy. But when there is an equilibrium between the vibrating mass and the radiated wave, I don't see how to partition energy between the vibrating and EM wave. Is it considered to be 50:50? I don't need all of the details, just the overall framework would be fine.
The nice thing about the equipartition theorem is that it is so simple and does not require you to know the details! Given any system consisting of components with energies $E$ that are quadratic in some variable, the equipartition theorem says that in equilibrium, the average energy of the system will be $kT/2$ for each of these components.
If we have $N$ particles with kinetic energy, which is quadratic in the momentum $E\sim p^2$, the average energy is $k N T / 2$.
For the electromagnetic field, the energy of each mode is quadratic in the electric field $E^2$ (sorry that $E$ now means electric fields and not energy!). If there were $N$ modes, the average energy would be $k N T / 2$. Since $N\rightarrow\infty$ for a real box, the average energy is infinite. The problem is to find a hole in this argument -- it isn't easy because Maxwell's equations are 100% unambiguous that the energy of each mode of the field is proportional to $E^2$, and the equipartition theorem suffers no exceptions, if its assumptions are satisfied.
The resolution to this utter mess -- which you are right, is obviously an absurd result -- is that Maxwell's equations are wrong. There is a minimum energy $h f$ needed to excite a mode with frequency $f$. This minimum value of the energy violates the assumption of the equipartition theorem that the energy is quadratic (since a quadratic function continuously approaches zero without a discrete step).
Here's an intuitive picture I like -- although it is not precise and your mileage may vary. The equipartition theorem says that energy likes to spread out as much as possible -- democratically distribute itself among all possible modes. Quantum mechanics prevents this from happening by imposing a cost for exciting high energy modes -- $hf$ becomes very big for high frequency modes, and so it "costs" a huge amount to excite the high energy modes, and so this barrier prevents the energy from spreading to these modes.
As a disclaimer / aside: while Maxwell's equations are wrong in an important way for explaining blackbody radiation, obviously they are also incredibly successful and they are not "wrong" in the sense that we should toss them out. Quantum mechanics has to be able to reproduce all the successes of classical electromagnetic theory when quantum mechanics is not important -- and indeed, it does.