As a layman out of the U.S. can somebody in economics tell me why the U S Govt bailed out the banks ?

Was it a free lunch or were there conditions behind the bail out, is what I am interested in. I know the collapsing of the banks due to heavy loan disbursements against mortgages. They collapsed because the people having taken those loans, lost them in the Stock market etc and they cannot repay the loans and instead preferred to surrender the mortgaged property to the Banks.