In the cavity-QED architecture, photon number fluctuations from residual cavity photons cause qubit dephasing due to the AC Stark effect. These unwanted photons originate from a variety of sources, such as thermal radiation, leftover measurement photons, and crosstalk. Using a capacitively-shunted flux qubit coupled to a transmission line cavity, we demonstrate a method that identifies and distinguishes coherent and thermal photons based on noise-spectral reconstruction from time-domain spin-locking relaxometry. Using these measurements, we attribute the limiting dephasing source in our system to thermal photons, rather than coherent photons. By improving the cryogenic attenuation on lines leading to the cavity, we successfully suppress residual thermal photons and achieve $T_1$-limited spin-echo decay time. The spin-locking noise spectroscopy technique can readily be applied to other qubit modalities for identifying general asymmetric non-classical noise spectra.