Light does not loose energy at all.
The energy of light (or formulated differently: the color of light) depends on the reference frame that you use to measure it. The theory of relativity spells out the details. The reference frames which are most practical to use, are "moving with the flow" of matter in the homogeneous expanding universe. For example, a practical reference frame for ourselves is the frame which moves with our galaxy, our milky way.
The crucial thing is that reference frames that "move with the flow" in different places, move with respect to each other. This makes a value measured for energy or color different for different reference frames. When a ray of light is emitted from somewhere in the universe, it makes sense to express its energy / color in the reference frame of the local matter around it at the event of emission. And when the same ray of light is absorbed, the reference frame of the local matter around it at the event of absorption. The apparent loss of energy is an artifact of using different reference frames.
If we always expressed the energy of the ray in the same reference frame, there would be no change in energy. But such a reference frame would not be very practical to use for the universe as a whole: some parts of of the universe would be at rest in it, other parts moving, so it could lead to the wrong idea that the universe is not homogeneous.
It would all be the easier if we could have a reference frame that (1) is an inertial reference frame, so measurements yield the same everywhere, every time, and (2) moves with the flow of the universe. But the particular motion (the expansion) of the universe makes that combination impossible.