There’s a cost-benefit component missing from the analysis.
“Bad” code is probably “good enough for now” code that was written some time ago on a bet that doing it better would never be needed as it wouldn’t need to change.
Also, “good” code is costly especially if taking longer to build the thing causes the company to miss its market.
In my experience a lot of bad was bad even when it was written. And that writing good code is often cheaper (within reason, perfection is bad) over any project bigger than a couple of months. The payoff from having good code shows up very quickly.