Shortly after the Big Bang, in the Planck era, the universe was about 1032 Kelvin hot. Afterwards it expanded rapidly and cooled down as the energy spread over an ever larger space. By and large, this process should continue as long as the universe expands – an end to the expansion is not yet in sight, on the contrary.
But there is a process that counteracts this cooling – at least temporarily. It is easy to understand. When 10,000 people go home from a football stadium, the mood cools down initially as the density of people decreases. But when a few fans get together to celebrate, things get hotter again. The formation of structures is also responsible for the warming of the cosmos. When gas masses clump together with dark matter halos to form galaxies, their particles heat up.