We examine in detail the mechanisms behind thermalization and Bose-Einstein condensation (BEC) of a gas of photons in a dye-filled microcavity. We derive a microscopic quantum model, based on that of a standard laser, and show how this model can reproduce the behavior of recent experiments. Using the rate-equation approximation of this model, we show how a thermal distribution of photons arises. We go on to describe how the nonequilibrium effects in our model can cause thermalization to break down as one moves away from the experimental parameter values. In particular, we examine the effects of changing cavity length, and of altering the vibrational spectrum of the dye molecules. We are able to identify two measures which quantify whether the system is in thermal equilibrium. Using these, we plot “phase diagrams” distinguishing BEC and standard lasing regimes. Going beyond the rate-equation approximation, our quantum model allows us to investigate both the second-order coherence g(2) and the linewidth of the emission from the cavity. We show how the linewidth collapses as the system transitions to a Bose condensed state, and compare the results to the Schawlow-Townes linewidth.