A star can grow hotter by losing energy. Gravity makes the difference. When energy escapes from a star and is not fully replaced, the star contracts; as its gas falls inward, gravitational energy is released, and some of it becomes the motion of particles that we measure as heat.
The accounting is stranger than it sounds. For a stable, self-gravitating star whose pressure comes largely from ordinary gas, the virial theorem implies that contraction releases enough gravitational energy to heat the gas while the rest escapes into space. The star has negative heat capacity: its temperature rises even as its total energy falls. This is not an unlimited trick. Pressure increases as the gas heats, resisting gravity and allowing the star to settle toward a new balance.
That balance is the quiet architect of a star's life. In a hydrogen-burning star, a cooling core contracts and heats, increasing the rate of nuclear fusion; greater outward pressure then checks the contraction. As hydrogen runs low in the core, the balance changes: the core contracts and heats while outer layers can expand, turning a Sun-like star into a giant. Later stages depend on the star's mass, and the simple gas-pressure picture breaks down when electron degeneracy becomes important. Above any orbiting planets, the light carries away the energy that helps change the star itself.