Because its nuclear furnace produces an enormous amount of heat pressure causing the atoms in the Sun to have just enough energy ( thermal kinetic energy) to balance their mutual gravitational attractions ( potential energy). The result is a star, burning happily, and existing in a state called 'hydrostatic equilibrium', although of course no 'water' is really involved! When the nuclear fires wane a bit, the star collapses slightly, causing the nuclear fires to burn a bit hotter. This causes an increase in the outward pressure and stabilizes the star.