It gets attenuated.Photon's energy is decreasing. Where does it go?
Think of the universe as analogous to an ideal gas in a closed vessel. The temperature will change in inverse proportion to the volume change.
i.e. increase the volume, and the temperature drops, though no energy has left the system.