The luminosity of a star is determined by its size (radius) and temperature. A star's luminosity is proportional to its surface area times the fourth power of its temperature (L ∝ R^2 x T^4), according to the Stefan-Boltzmann Law and the relationship between the luminosity and temperature is known as the Hertzsprung-Russell (H-R) diagram.
Red giants are much larger than red dwarfs, which means that they have a much larger surface area and thus emit more energy. Although red giants have cooler surface temperatures than red dwarfs, their larger surface area more than makes up for the lower temperature in terms of total energy output.
The reason why red giants are much larger than red dwarfs has to do with the evolution of the star. Red giants are more evolved stars that have exhausted the hydrogen fuel in their cores, causing the core to contract and heat up, while the outer layers of the star expand and cool down. This expansion increases the star's size and surface area, leading to a higher luminosity.
Red dwarfs, on the other hand, are much smaller and cooler than red giants because they are low-mass stars that burn their fuel at a slower rate. As a result, they have longer lifetimes and remain on the main sequence longer, never undergoing the same expansion that red giants do.