The often cited reason is that young people are easier to manipulate and exploit (overtime, passion, kool-aid about the company "mission" etc.), or more charitably phrased are more "adaptable" and less set in their ways.
They have fewer responsibilities, no family etc. They are more idealistic and don't have the same cynical/sour/realist/seeing-through-the-bullshit outlook that older people have.
For hiring discrimination? I mean, that’s kind of a hard question to answer.
Personally I think there are lots of people who have an idea in their head (not always consciously) of what a hotshot developer looks like. And it’s not the old guy. And I think this manifests as concerns about “culture fit” or being overqualified or other vague objections.
We ALL have biases. It’s on hiring managers and HR departments and all of us to actively work to minimize their effects. This is hard to do and, unfortunately, some people don’t care to try.
But certainly there are other reasons too. Bias in hiring is a tough problem.