It's super easy to look back and think, "it really doesn't matter where you went to school." and it's true, I've met people who went to no-name schools and get employed at great companies.
But put yourself into the shoes of an impressionable 16-17 year old. Private and flagship public universities have mastered selling their product with tours, special programs, the "college experience" etc. In addition, they sell getting a job with countless networking opportunities (especially prestigious schools).
It'd be really efficient for anyone who would need loans to get a degree to knock out all gen eds at a comm college and then transfer to an in-state university (it makes zero sense to pay 30-55K a year to take an entire schedule of calc 1 and chem 101). But it's hard to blame a 17 year old for taking the more fun and cooler option than the practical one.
I suppose if government and states invested heavily into community colleges and made them "cool" with great facilities and opportunities, more kids can be incentivized to go that route and avoid the heavy loans.