I'm going to assume you have learned about Newton's Law of Gravity already.
This thought experiment relies on something that Newton first proved a while back, and what you might have been told in school without much explaining - that gravity far away from a spherically-symmetric mass is the same as if all the mass were concentrated in its centre. That's why you can calculate the acceleration due to gravity on the surface of Earth as if all its mass were in its centre, 6700-odd km away.
It's what is called the 'shell theorem', and it can be understood if you know some calculus, or purely on geometrical terms - look it up on Wikipedia.
The other thing the theorem shows is that the gravitational field
inside a spherically symmetric, empty shell of matter is always 0.
Imagine a set-up like this:
View attachment 81178
You've got a hollow shell of mass M represented by the grey circle. The shell contracts under its own gravity until it is smaller - here represented by the black circle. It doesn't matter how far it had actually contracted when we look at it again. The point is, it's smaller than before.
The gravity field (i.e., acceleration due to gravity, or ##F/m##) outside this shell (at point A) is the same as if all the mass were concentrated in the centre of the circle and given by ##g=\frac{GM}{R^2}##.
The field inside the grey circle
before it contracted is zero throughout the volume, including points B and C.
Now let's look at it after it contracted:
-the field outside the original radius (outside the grey circle, point A) is still the same, because we can still treat it as if the mass were concentrated in the centre;
-the field inside the new radius (inside the black circle, point C) is still zero, because this volume is still surrounded on all sides by spherically-symmetric shell of matter;
-the field between the two radii (point B) is now equal to ##g=\frac{GM}{R_B^2}##, whereas before the shell contracted, it was zero.
So what you've got, is gravity appearing in a volume of space where once it wasn't there.This works the other way around as well. Imagine a star exploding (for simplicity, let's say it doesn't leave anything behind - like a supernova type Ia explosion).
Before it explodes, a planet can be in orbit around it due to the gravity it feels from all that mass.
After it explodes, the gravity that held the planet in orbit disappears as soon as the 'shrapnel', i.e. the envelope of matter ejected by explosion, passes the planet's orbit. Now the planet is inside an expanding, spherically symmetric and hollow shell of matter, and the value of the gravitational field it experiences is zero.