Yes, if your mortgage lender goes bankrupt you do still need to pay your mortgage obligation. Sorry to disappoint, but there is no free lunch in this situation. If your mortgage lender goes under, the company will normally sell all existing mortgages to other lenders.
In most cases, the terms of your mortgage agreement will not change. (Be sure to check your mortgage agreement for "sale and assignment" terms.) The only difference is that the new company will assume responsibility for receiving payments and for servicing the loan rather than the company you originally dealt with. Together, the Federal National Mortgage Association (Fannie Mae, or FNMA) and the Federal Home Loan Mortgage Corp (Freddie Mac, or FHLMC) purchase or guarantee 40-60% of all mortgages originating in the United States. (To learn more on this subject, see Behind The Scenes of Your Mortgage.)
Also, we must note that it is normal business practice for some lenders to sell their mortgages to other companies in situations outside of financial distress. You can check this by reviewing your original loan agreement. Within your documentation, you'll find a section that defines the responsibilities of each party if the mortgage is sold or assigned to another company.