What does Gauss' divergence theorem say about compression of a body under self-gravitation? Below this question there is a comment that caught my interest:


  First, there's a misconception. Compressing a body does not increase the force of gravity on outer-lying masses. That's Gauss's famous divergence theorem.


I understand that one can use the divergence theorem to address (derive) the shell theorem - one consequence of quick is that a particle inside a spherically symmetric shell experiences no net gravitational force from the shell, but this seems different as it refers changes in average density of a body and gravitational forces on outer-lying masses.

So I'd like to understand better: What does Gauss' divergence theorem say about compression of a body under self-gravitation?

For reference, this answer covers the shell theorem nicely.
Gauss's divergence theorem applied to the gravitational field $\vec{g}$ is that
$$ \oint \vec{g} \cdot d\vec{A} = \int \nabla \cdot \vec{g}\ dV,$$
where the left hand side is the flux of gravitational field into/out of a closed surface and the right hand side is the integral of the divergence of that field over the volume enclose by the surface.

The fundamental definition of how mass produces gravitational field is that
$$ \nabla \cdot \vec{g} = -4\pi G \rho,$$
where $\rho$ is the mass density.

If you are at a point outside the mass then the right hand side of the divergence theorem  becomes a constant.
$$ \oint \vec{g} \cdot d\vec{A} = -4\pi G \int \rho\ dV = -4\pi GM.$$
Therefore the left hand side is also constant when calculated over any surface that encloses all the mass.

If you allow the mass to contract in a spherically symmetric fashion, then as the gravitational field on the left hand side is then always in the radial direction then $\vec{g}$ must stay the same at any position in space outside the mass distribution.