While applying the principles of statistical mechanics to a photon gas, why do we use the partition function for a simple harmonic oscillator? I'm trying to follow the derivation of the Stefan-Boltzmann constant in the Thermal Physics textbook written by Blundell and Blundell. And after deriving the density of states $g(\omega) d\omega$, the text proceeds to take the partition function of a photon gas (blackbody radiation, in this specific case) as the one for a simple harmonic oscillator.
If photons cannot interact with each other and their paths cannot be diverted by a "potential" of any sort, why would one use the configuration of a simple harmonic oscillator? If anything, since these photons are in a blackbody cavity, would an infinite square well not suffice (with the added bonus of not having to deal with the diverging zero-point energy)?
 A: I think your perplexity originates from a too simple idea about what a photon is. 
But, before discussing issues related to the full-flag  concept of photon, let me address your question in a simpler way. For that you have to forget any idea about photons.
Let's go back to the blackbody radiation as a system made by electromagnetic radiation in thermal equilibrium inside a cavity. What is its classical description  as dynamical system? Dynamics of the e.m. field is described by the set of Maxwell's equation in the vacuum plus boundary conditions at the walls of the cavity.
It turns out  that it is possible to recast the redundant description of the radiation as electric and magnetic fields in term of a vector potential ${\bf A(r},t{\bf)}$ which is an infinite set of two-components vector plane waves, one vector amplitude per each plane-wave of wave-vector ${\bf k}$ and frequency $ \omega_{\bf k}= c \left| {\bf k} \right| $ ($c$ being the speed of light). The equation of motion for each Fourier component of the vector potential (normal modes of the field) is exactly in the form of a  simple harmonic oscillator of frequency $ \omega_{\bf k}$.
A purely classical treatment of the system of the non-interacting normal modes through statistical mechanics would result in the so-called ultraviolet catastrophe (equipartition theorem would imply a divergent energy density in the system). Therefore a quantum treatment is called for. The simplest way to achieve it is to quantize all the harmonic oscillators describing the vector potential. This step immediately provides for each normal mode (each ${\bf k}$ and each of the two components $s$) a spectrum of allowed energies 
$$
\varepsilon(n_{{\bf k},s})= \hbar \omega_{\bf k} \left(n_{{\bf k},s} + \frac12 \right)
$$
Each state of such a system of quantized normal mode is fully described by the set of all the infinite quantum numbers $\left\{ n_{{\bf k},s}\right\} $. 
That's all for doing statistical mechanics: we have a way to identify all the microscopic states (one state a characterized by a different set of $\left\{ n_{{\bf k},s}\right\} $) and to assign an energy to this state. Of course, it is possible to introduce a density of states and to perform all the usual manipulations of the formulas.
As you can see, in all the previous discussion, photons have not entered explicitly.
They can be introduced, by noticing that the expression for the energy of a microstate could be interpreted as if there were $ n_{{\bf k},s} $ 'particles', each with energy $\hbar \omega_{\bf k}$. Moreover, it is possible to show that the momentum of such a quantized dynamical system is also well defined and again behaves as if the were $ n_{{\bf k},s} $ 'particles', each with a momentum $\bf k$.
The combination of these two observations, plus the fact that if one of such 'particles' exists, its momentum is never changing, is the starting point to justify the introduction of the concept of photon and gas of non-interacting photons. Consideration on the momentum and its conservation are clearly as important as the form of the energy spectrum.
A final word of caution. Photons come out from the quantized description of the e.m. field. There is nothing in the formalism which allows to speak or to justify the concept of a classical trajectory or path. This is the reason, I started my answer saying that your question contains a too simple idea about photons.
