Final answer:
A star stops contracting when the internal pressure, elevated by heat, counteracts gravity. This balance is called hydrostatic equilibrium. Stars in their final collapse are supported by electron or neutron degeneracy pressure until possibly forming a black hole if sufficiently massive.
Step-by-step explanation:
A star stops contracting when it becomes hot enough that its internal pressure, due to the heat, builds up and pushes back against the force of gravity. During the early stages of a star's life, as a protostar, it contracts and heats up, radiating away energy. If a star were to contract further, it would require electrons to exist in the same state at the same place, violating the Pauli exclusion principle, and thus it reaches a state of hydrostatic equilibrium. In this state, internal pressure balances the gravitational forces trying to compress the star further.
For stars like the Sun, when they exhaust their nuclear fuel, they can't maintain the necessary heat to push back against gravity and begin to collapse. They are supported by electron degeneracy pressure, or in the case of more massive stars, potentially neutron degeneracy pressure. Ultimately, if the core's mass is more than three times that of the Sun, it may collapse into a black hole, as no known force can stop the gravitational collapse.