Generally speaking is not possible to assert if the energy is conserved in General Relativity (GR). There are several subtle points about the definition of the energy of the gravitational field and how this could introduce a concept of total energy (including gravitational energy), however, here I will discuss only the energy of the matter content.
In some cases one can prove that the total energy of the matter content is indeed conserved. The total energy momentum tensor (EMT) $T_{\mu\nu}$ must satisfy $$\nabla_\mu{}T^\mu{}\nu = 0.$$ These conditions come from the <PERSON> identities along with the <PERSON>'s equations. 469
Given some timelike vector field $v^\mu$ it is possible to define the energy momentum flow through the foliation defined by $v^\mu$ as $P^\mu = T^{\mu\nu}v\nu$ (not all timelike vector fields define a global foliation, however, I will ignore this point here).
The vector field $P^\mu$ has its divergence given by $$\nabla_\mu{}P^\mu = \nabla_\mu{}T^{\mu\nu}v_\nu + T^{\mu\nu}\nabla_\mu{}v_\nu = T^{\mu\nu}\nabla_\mu{}v_\nu = T^{\mu\nu}\nabla_{(\mu}{}v_{\nu)},$$ where the parenthesis represent the symmetric part and the last equality comes from the symmetric property of the EMT. If for some reason $\nabla_\mu{}P^\mu = 0$, then the <PERSON>'s theorem (plus some conditions on the manifold or on the EMT at infinity) guarantees that the total energy is conserved, i.e., $$\left.\int\mathrm{d}^3x\sqrt{\gamma}P^\nu{}v_\nu\right\vert_{t_1} = \left.\int\mathrm{d}^3x\sqrt{\gamma}P^\nu{}v_\nu\right\vert_{t_2},$$ where $\gamma$ is the determinant of the metric projected on the spatial hypersurface defined by $v^\nu$ and $t_1, t_2$ are two labels defining two different hypersurfaces.
If $v_\mu$ is a Killing vector field it satisfy $$\mathcal{L}v g{\mu\nu} = n^\alpha\nabla_\alpha{}g_{\mu\nu} + 2\nabla_{(\mu}v_{\nu)} = 2\nabla_{(\mu}v_{\nu)} = 0,$$ where we used the covariant derivative compatible with $g_{\mu\nu}$. This shows that, if there is a timelike Killing field then the total energy is conserved, however, the converse is not true, i.e., the following statement is not true: if the total energy momentum is conserved then there is a timelike Killing field.
In our current cosmological model, the universe (at zero order) is described by a Friedmann-Lamaître-Robertson-Walker (FLRW) metric which do not posses a timelike Killing vector. This is why the energy of a radiation-like fluid is not conserved, from the direct calculation of the EMT divergence in a FLRW model we have $$\dot{\rho} + 3H(\rho+p) = 0,$$ where $H=\dot{a}/a$ is the <PERSON> function, $a$ the scale factor, $\dot{f} = v^\mu\partial_\mu{}f$ the time derivative of a scalar function $f$, the EMT is given by $T_{\mu\nu} = \rho{}v_\mu{}v_\nu + p\gamma_{\mu\nu}$, $v_\mu$ is the field represent the fluid flow, $\gamma_{\mu\nu} = g_{\mu\nu} + v_{\mu}v_{\nu}$ is the spatial projector, $\rho$ the energy density in this frame and $p$ the isotropic pressure also in this frame. 578