The way you it put that makes it sound as though you are confusing two
things. For a start, gravity does not push away the outer layers.
Try to
imagine this analogy:
You have a pot on the stove with a closely fitting lid, and it contains
boiling water with steam forcing its way out between the lid and the pot. Let us assume that it is boiling at a temperature of 100°C. This
does not suit you, so you press down on the lid to prevent the steam from
escaping by forcing its way out.
However, by pressing down, although you keep the steam inside, you cause
the temperature to rise and you press the bottom of the pot into closer connection
with the stovetop, thereby inproving the heat conduction into the bottom of the pot and increasing the rate of heat flow. Pretty soon the
steam is forcing its way out and escaping faster than ever, and this process continues until the pot
boils dry.
Notice that the pressure that you apply does not remove steam any
faster. You could demonstrate this at any time by suddenly letting go and removing the pressure that you had applied. Instead of the escape of the steam slowing down when you remove the pressure, at that
point the steam really starts to escape at a great rate, possibly even explosively, and it continues to do so
until things settle down again.
Now, without going into too much detail, think of the star. The heavier
the pressure with which gravity presses the outer layers of gas against the core of the
star, the hotter the core becomes, and the faster the nuclear
reactions run inside the core, producing yet more heat, and faster than before. The
hotter the particles in the core, the more vigorously they in turn apply pressure
against the outer layers. Depending on the kind of sun, and how large it
is, their outward pressure actually may force it to expand into a giant of one kind or another.
For example we expect our Sun to become a red giant in perhaps another billion
years or so.
However, this can go on only for so long. Sooner or later the star must run out of
nuclear fuel and then the "nuclear burning" simply must stop.
After that the star begins to cool, and because it cools it must shrink.
If it is big enough and its outer layers shrink fast enough and symmetrically
enough, they fall onto the central core with an almighty bang, and partly from
their own momentum and partly from the nuclear reactions resulting from that
crunch, they rebound into space.
That is what we call a supernova.
Notice that gravity did not throw anything out into space. In fact,
rather like when you press down on the lid of your pot of boiling water, gravity actually
resisted any tendency for anything to move away from the core of the star. What
actually threw all the stuff out was the combination of the bounce and the sudden
flood of heat and particles (particularly neutrinos, amazingly enough!) that
were released by that final gravitational and inertial squeeze.
I hope that helps. If not, then please ask again.