There are many reasons why people attend community colleges.
Yes, one reason is that they didn't achieve the grades and test scores needed to attend a four-year school.
But there are many other reasons.
Some are at community college as a cheap way to do their first two years of colleges (cc's are typically much less expensive than universities).
They are at the cc to learn a trade (such as electrician)
They are attending the cc to earn a certificate, and have no interest or need to attend a university
They are an adult learner where the cc is a much better option, since cc's tend to have a lot of evening classes for working students
They already have a four-year degree but need to pick up a specific course or two for their professional advancement, or because of a personal interest
Many cc's offer free tuition to seniors who wish to audit courses in subjects they find of interest. So, you'll often see people in their 60s and 70s in courses such as art history.
The cc is a lot closer to where they live than a four year university, and offers the opportunity to live at home while taking courses
Some four year schools more or less urge their students to pick up required courses, which could include calculus and chemistry, at the cc, where the pace of instruction is often slower and there's more of an emphasis on working with students who are having trouble with the material.
Four year students often spend their summers at a cc picking up additional courses that will be applied to their university program.