The banks don't take a loss because it's the Department of Education loaning the money.
Direct Stafford Loans, from the William D. Ford Federal Direct Loan (Direct Loan) Program, are low-interest loans for eligible students to help cover the cost of higher education at a four-year college or university, community college, or trade, career, or technical school. Eligible students borrow directly from the U.S. Department of Education (the Department) at participating schools.
The banks don't take a loss because it's the Department of Education loaning the money.
https://www.benefits.gov/benefit/4370
These loans can't be discharged in bankruptcy for that very reason.