We’re asking why a company would still have share value if it is bankrupt. People are betting that the company has value beyond the debt. Debt gets worked out all the time. Junior debt gets converted into equity. Senior debt gets a new payment schedule and maturity date. In many cases, bringing the interest rate down or converting it into a kicker gives value back to the shareholders.
That is true of a chapter 11 bankruptcy, but not of a chapter 7. In the later case, all assets go to the bondholders, and there is no equity left for the former stockholders, who are left holding a worthless corporate shell.
This is certainly the case with WaMu and Lehman. Even the bondholders took big losses.