When people say this, they are implying that choosing to get a higher education that creates student loan debt is equal to some other choice that wouldn't incur that debt. But of course, this is untrue; the benefits of a quality education are not equivalent to other options. It's not just "student loans or no student loans" in isolation.
To make your analogy somewhat more accurate (though probably still imperfect): it's like the teacher says "study chapters 1-5 and I'll give you a 90% guarantee in the class, and those chapters will be on the test", then the test ends up being only chapter 3. Yes, you spent the extra time studying you didn't need, but you still got the 90% guarantee in the class, so the time debt paid off even if the people who didn't study as much got to hang out with friends more, since they didn't get that 90% guarantee.