The Rayliegh-Jeans law can be derived by treating the radiation as a superposition of standing waves in the enclosure. There are an infinite number of possible standing waves. Each standing wave is treated like a harmonic oscillator in terms of its ability to store energy.
According to classical statistical mechanics, a collection of harmonic oscillators in thermal equilibrium at temperature T will store energy such that, on the average, each oscillator will have kT of total energy with kT/2 as kinetic energy and kT/2 as potential energy. Thus, an oscillator acts like a system with "two degrees of freedom" since according to the classical equipartition of energy theorem, each degree of freedom stores kT/2 of energy.
So, each standing wave mode of radiation in the enclosure is assumed to act like an oscillator with 2 degrees of freedom. (The total number of degrees of freedom of the radiation is infinite since there are an infinite number of standing wave modes of higher and higher frequency. Hence, the "ultraviolet catastrophe".)