It’s a matter of who gets paid first. To oversimplify...
Let’s say I have a company with 100M in debt. If the company is sold for 150M. The first 100M goes to pay debt. The other 50M goes to the owners. If it’s sold for 300M, then 200M goes to equity. They get all the upside. On the flip side if the company sells for less than 100M, the all the money goes to the debt holder.
What’s going on is debt holders trade upside for downside protection. Equity holders give up downside protection to get equity.
Life is a little more complicated (some equity holders have more protection than others, and some equity holders may be debt holders) but usually it’s just trading off upside for downside or vice versa.