They do it because of the Civil Rights Act of 1964:
The Civil Rights Act of 1964 (Pub.L. 88–352, 78 Stat. 241, enacted July 2, 1964) is a landmark civil rights and US labor law in the United States[5] that outlaws discrimination based on race, color, religion, sex, or national origin.
And also the Age Discrimination in Employment Act of 1967
The Age Discrimination in Employment Act of 1967 (29 U.S.C. § 621 to 29 U.S.C. § 634) is a US labor law that forbids employment discrimination against anyone at least 40 years of age in the United States
You see, they aren't passing on you based on race, color, religion, sex, national origin, or age; it's because you are overqualified, or not a cultural fit. It's like the "IT'S COMING RIGHT FOR US!" loophole in South Park.
I'm not sure that's true. If they don't want to hire you, they're less likely to, but at some point it might not be worth the effort to come up with an excuse. And, importantly for an organization, "they" might be a subset of people. If I have a biased coworker (where "biased" can be anything, but let's go with age for now) who doesn't want to hire someone, but can't communicate their dislike in email without putting animus towards a protected class in writing, and the rest of the team is mildly positive, the fact that they couldn't be brutally honest is probably enough to go from a no-hire (via the coworker's veto) to a hire.
About a decade back, I applied for a job in Dunedin. The manager of it met me, read my resume and loved it - I had plenty of experience where the other applicant he was interviewing didn't have any, he said, and queried what I knew about this and that, so on. He couldn't have been more positive.
Then he asked if I had any medical problems, I told him I have a disability.
The red started at his collar and worked his way up to his face. He made a point of going back to my resume, and loudly shouted at me for not having any relevant experience, how I'd fking wasted his time and he was going to bill me for it, that he was going to lay a formal complaint with the employment agency I had gone through. He lied through is teeth about their work for the city council, that he "ran the computer systems for them, all the servers," and that he didn't have time to teach me how computers worked, that I only had an academic qualification with no real world experience. (I knew a guy who was loosely involved with ITS for the DCC at the time, and he told me the interviewer is a liar, most of their IT support was in-house or specialist software support.)
The interviewer also told me that I should get "real world experience running a corporate network," and he told me I could do that by stealing old computers and pirating Windows ("Well, there are ways to get Windows.")
A few years later, I ran into a friend of mine from university who, it turned out, had got the job I missed out on. He was just out of university when they hired him, and actually had no experience in any roles of any sort.
tl;dr: The interviewer lied to my face. It hindsight, it was obvious that he did, but at the time I didn't get it. (Part of the disability, I'm very easily lied to.) He made up every excuse under the sun to not hire me, or even continue with the interview. It would have been much less obvious (to an outsider) if he'd just concluded the interview normally, without any further comments on the disability and I wouldn't have been any the wiser, but he was too stupid and self-righteous for that.
(Further thought, when I found out about it, I mentioned it to a friend of mine who immediately told me that the employer had every right to discriminate against me on the basis of my disability, and nothing could convince him otherwise - not even the government, who stated that had I found out sooner and been able to prove it, I would have likely received a large cash settlement.)
I think I phrased that wrongly - for individual people, having laws may or may not actually help you. (If I'm understanding you right, the law could have helped you, had you been advised correctly about it, but you weren't.) But for society as a whole, having the law means some people are going to be helped by it. Many aren't. But a social change always starts small.