The world is as we find it, not as we wish.
Of course learning does not have to be a side-effect of the university education. But then they’d have to find something other than exams to grade performance. And, in fact, some school do this. But for most of the major US universities (University of California, University of Washington — both my alma maters — , University of Illinois, etc…) the “education” process is structured around exams. Learning in such an environment is a side effect of the process.
If you want to survive in the university system you have to come to terms with the truth that you’re there to pass exams (and perhaps do homework sets).
It doesn’t have to be that way, but it is.
Many universities have research opportunities and if you do well in your coursework you can pursue these opportunities. As an undergrad that will allow you to get to know some of your professors and give you some good references.