Foreclosure is at a high level the bank declaring that the debtor cannot pay their promissory note (their debt). This is shortly followed by default, which is the removal of debtors rights to the property. After the debtor has defaulted, he either chooses to voluntarily remove himself and his belongings from the property, or is forcibly evicted. In the US eviction is carried out by local law enforcement, such as the sheriff's office.
The bank is now the sole owner of the property, and proceeds to sell it, in an attempt to recoup their investment. If the bank cannot recoup their investment by selling the house, the rest may be converted to unsecured debt against the debtor. If the bank chooses to forgive the remaining debt, the debtor may have a tax liability for cancellation of debt. Also the debtor may also be liable for any appreciation the house did before it was sold, but this likely to be nontaxable if the house in question is the debtor's primary residence.
They also send the credit bureaus the notice of foreclosure, which is how your credit score is hurt. Private Mortgage Insurance or Lenders Mortgage Insurance will pay the lender some amount back to cover their losses.