Gravitational compression
Gravitational compression is a process whereby gravity acting on the mass of an object compresses it, increasing its density and reducing its volume.
The Sun is a good example, wherein the surface of the Sun is pulled downwards by the Sun's own gravity. This causes it to push down on the layer immediately below, thus increasing the pressure, and therefore the density of that layer. The higher density allows more mass to be closer to the Sun's center, which increases the gravity, leading to a compounding effect. This extends all the way down to the solar core, where the pressure of all the layers above it causes the density to rise dramatically. Without this compounding effect, which results in a greater frequency of collisions between particles, nuclear fusion within the Sun could not occur.
The same process increases the density of other objects in the solar system to lesser degrees. It is responsible for the higher density of Saturn's moon Titan compared with the rest of Saturn's moons, despite Titan being composed of the same material as the other moons. The increase in gravitational compression with size also explains why Earth is the densest planet in the Solar System even though Mercury is composed of much denser materials and has a much larger core relative to its diameter.