Most people in high school aren't thinking super-hard about their careers. They're thinking about school and college. Even then, kids learn about "big" achievements - RNA, species classification, electron shells, WW2, White House scandals, etc. You're aspiring to be someone if you're in an area where you have scholastic resources, not just some programmer. You're not looking so hard at money. If you're in an impoverished area where graduation rates are abysmal and you're not even being taught science, the odds of being a professional athlete or pop star look about the same as going to college - a whole different set of challenges. Let's assume we're talking about high schools with resources to even have computer classes.
Paying more money doesn't make it a sexy profession - there are plenty of "famous" programmers that the HN crowd knows about, but none of their achievements are public. Creating a business like Amazon or Facebook doesn't have the same personal allure to most people like inventing a vaccine for polio does. I bet if you asked a classroom of high schoolers who Jeff Bezos is, 85% of the room would have no idea. There's no _personal glory_ to being a programmer.
With law, you can help people's lives directly - same with being a doctor. There's a social value to those professions that seems obvious and immediate (even though it might be far from the truth). Most people want to do good in the world, and being a programmer has no obvious correlation with that. It doesn't entice students because there's no history written about programmers, no scientific experiments you do in classroom, no math taught that correlates with programming. It's in academic isolation until college, and by then, it's too late.