Thank you for your thoughtful comment Ben.
Interest on a debt is determined by the level of risk the lender perceives, which drives how much they want to be compensated for that risk.
The risk is affected by the borrowers credit score, income, and assets; any collateral attached to the loan (as you say); and the current and expected inflation rate.
As you point out, good debt usually has lower perceived risk, because it may have collateral attached and/or increases the borrower's likely ability to repay (e.g., student loans, business loans, and possibly portfolio margin loans).
Also as you point out, interest rates tend to be highest for the worst-offender "bad debts" like credit cards and payday loans.
I'd modify a bit your statement that "If we were to narrow what matters down to one variable, it would be your ability to repay that debt." Instead, I'd say that your ability to repay is a major (though not sole) driver of interest rates.
One crucial thing has me insist that interest rate is far more important than "good" vs. "bad" debt, when choosing whether to invest or accererate payoff. It's that sometimes a lender gives you a super-low or even zero interest rate even on something that isn't normally considered "good debt."
For example, I bought two cars (pre-Covid) with zero-interest loans. Not many people would argue that a car loan is normally "good debt." Still, even if you call it "bad debt," it would make zero financial sense to pay such a loan any faster than required by the loan's terms.