The federal tax would be forgiven by the 2007 law, and CA doesn't have a law in line with that yet for state taxes, but it might adopt one that could cover this tax liability.
Even if not, your taxable capital gain would be calculated based on the cost basis of the property (what you paid for it, plus the cost of any improvements to it), and if that number is greater than the sale/foreclosure price, then you'd have no gain to be taxed on.
Get another opinion from a CPA, since they'd be the one defending you in any tax audit.
Disclaimer: Please note that this answer does not constitute legal advice, and should not be relied on, since each state has different laws, each situation is fact specific, and it is impossible to evaluate a legal problem without a comprehensive consultation and review of all the facts and documents at issue. This answer does not create an attorney-client relationship.
Also consider the possibility of getting a 1099 for the debt that the bank forgave in the foreclosure. You should consult a CPA on dealing with the "new" income as well.
Its also very difficult to respond to your tax question without having all of the numbers (as the CPA did). As such, I would defer to your CPA on that issue.
Disclaimer: Attorney's response is not intended as legal advice and is for informational basis only. Inquirer should seek the counsel of a duly licensed attorney within that jurisdiction.
The tax loss is only one part of the problem. You can also have income from debt relief which is the difference between the debt you owe and the amount the bank was paid back through the foreclosure. Discuss this part with your CPA or another tax professional.
Any individual seeking legal advice for their own situation should retain their own legal counsel as this response provides information that is general in nature and not specific to any person's unique situation. Circular 230 Disclaimer - Advice given in this response cannot be used to eliminate penalties with the IRS or any other governmental agency.