Debt usually is senior and paid first if a business is sold. But not always. In the case of startup debt, loan terms can be non-standard because VCs who own preferred shares don't want to subordinate their stake. It depends on the terms sheets, debt might be senior to everything or it could be treated as equal to the later stage VC investors preferred shares preference (also called "pari passu" if you want to sounds like an arrogant tool lawyer).
You're right it would take a surprise total catastrophe for principle to be wiped out. But the principle isn't always the main worry for startup lenders. Well it is, but the loan terms are written in such a way lenders are confident they will get some or all of the principle back. The big worry and risk for lenders is usually time. Being paid back too soon or being paid very late are both risks (the latter happens in bankruptcy cases where court system can take a long time to get lenders their money back).