The universe was a thermal plasma prior to the recombination epoch, consisting mostly of photons, protons, electrons, and alpha particles (helium-4 nuclei). There were also a small portion of deuterium, helium-3, and lithium-7 nuclei. All of this primordial stuff was in thermal equilibrium. The temperature of a gas is a result of the random velocities of particles that form the gas. In the case of the pre-big bang universe, the protons, electrons, beta particles, etc. in that soup had a "temperature" because of their random velocities.
What about photons? How can light have a "temperature" (and how can it be in thermal equilibrium)? The answer lies in thermal radiation. This radiation has a rather unique frequency signature called black body radiation. Non-thermal radiation (e.g., a laser) doesn't look anything like a black body. Whether the spectrum of some radiation signal is close to or far removed from that of an ideal black body is what distinguishes thermal radiation from non-thermal radiation. If the spectrum is close to that of an ideal black body, one can say that the radiation effectively does have a "temperature."
The light in a fully ionized thermal plasma is in thermal equilibrium with the other stuff that comprises the plasma if the spectrum of that light is close to that of an ideal black body and if that effective temperature is equal to that of the temperature of all that other stuff. Thermal equilibrium can occur in a plasma because light is constantly being scattered, absorbed, and re-emitted. This was the state of the universe prior to the recombination epoch.
Once the universe cleared, the photons previously in thermal equilibrium with the universe's ordinary primordial matter decoupled from that matter. Those photons instead were free to traverse the universe. An observer at the time of that event would have seen those first-freed photons as having a black body temperature of about 3000 K, the same temperature as that of the ordinary matter with which the photons were previously in thermal equilibrium.
Red shifted black body radiation retains the key characteristic of black body radiation, which is a spectrum that follows that of an ideal black body. However, the effective temperature of that red shifted spectrum is lower than the effective temperature prior to the red shifting. Thirteen-plus billion years after that recombination event, we see a red shifted background radiation that still looks very much like that of a black body, but with an effective temperature of only 2.726 K instead of 3000 K.