So I'm staring down the bore of my 40th birthday.
That means that I graduated college in 1999. When I was looking at colleges (in 1995), many of the colleges that I looked at didn't have a computer science department. Many of the ones that did, had had that CS department for less than five years.
My class ('99, again) had twice as many CS majors as did '98. '00 had twice as many CS majors as '99 -- because this was the first dot-com boom, of course.
At my college, my freshman year was the first year that every dorm room was wired for ethernet (obviously, wifi was not a thing).
I suspect that the arrow of causality goes two ways, and that part of the reason for the low median age of programmers is indeed age discrimination. But it also true that 40 is an age which means that you were college-age during the first dot-com boom, and the occupation "programmer" suddenly was looking a lot more attractive and absolutely no doubt was pulling in a bunch of young people who ten years earlier would not have been interested in being programmers.