When you take out a mortgage or buy dinner with a credit card, you're borrowing money, but not earning income. Loans aren't taxable income because they're temporary. You pay them back, often with interest, so you're not any richer for borrowing the money. Loans only become taxable if you don't pay the lender back, or the IRS decides that your loan was a tax scam.
If you're too broke to repay your credit-card company or any other lender, getting the debt written off probably doesn't feel like you earned money. The government disagrees, and requires the unlucky lender to send you a 1099-C showing the amount of the canceled debt. You add the amount in when calculating your gross income on your 1040 and pay tax accordingly. Bankruptcy is an exception: if you wipe out debts that way, there's no tax.
If you default on your mortgage, you may not have to pay tax on the amount you didn't repay the bank. The IRS doesn't count mortgage debt on your primary home as income, provided it's no more than $2 million, or $1 million for married couples filing separately. Larger amounts or forgiven debt on rental or second homes doesn't qualify. At the time of writing, the law covers mortgage debts if they're forgiven before the end of 2013.
There are other circumstances in which the IRS cuts you some slack. For example, if you borrow money from your mother and she cancels the debt as a gift, or in her will, there's no tax to pay. When a student-loan lender cancels your debt in return for services -- you work for charity for a year after graduating, say -- that isn't taxable. If you can show the IRS you're insolvent, with more debts than income, the IRS waives the canceled-debt tax.
Not a Loan
The IRS has cracked down on borrowers in some tax cases, on the grounds they were were covertly selling assets rather than taking out a loan. In one early 21st-century case, a taxpayer borrowed $13.5 million against securities he used as collateral. The lender sold off the securities and the borrower never repaid the loan. The IRS charged that the loan was a cover for the taxable sale of securities, took him to tax court and won.