Jobs aren't paid by necessity. In fact, I would say the opposite is true. We need garbage persons, construction crews, truck drivers, etc to make society function. Yet, these people aren't paid that great. Conversely, do we need another programmer at Google? Do we need an all-star quarterback for our home team?
Well you've kind of hit on the answer there. Jobs are paid on their productivity. A garbage man doesn't offer the economy very much. A programmer at Google does. Divide the number of Google programmers by the amount of money google rakes in ... they bring in a lot each. A quarterback even more. How many shirts does that guy sell? How many people tune in and watch the game + adverts because he's there. He brings in more for the club than developers do for google ... and gets paid a shit load more too.
And then we come to teachers. You teach a bunch of 10 years olds long division. How much GDP are those kids going to subsequently add this quarter because of those efforts? School teachers contribute absolutely zero to the economy. Less so than a McDonalds worker, and yet they still get paid more. If anything teachers are paid too much.
Now you could take the view that without teachers there would be no google developers nor quarterbacks from colleges nor McDonalds workers who can count money to use a till, and that all wealth is derived from teachers ... but that is just stupid talk.
The truth is some teachers add to GDP, the ones who train foreign students and those who pay tuition fees to colleges. Its not a huge amount, but its why they get a bit more than McDonlads workers and less than Google developers. Teachers get what they deserve.