I think this would be illegal under the Equality Act (which does not of course mean it doesn't happen), can you offer some examples or further reading?
Until then, you are quite correct. The pay gap is not a feature of individual jobs, but a population effect due to women in their 40s+ not being in the labour force.
It is illegal in the UK to pay differently, and there are many high profile cases of this being enforced even to the point of absurdity (such as forcing councils to pay bin-men/trash-collectors the same as female office admin workers).
Likewise as the mean pay for women is ~1month/yr lower, the mean hours men work, as a population is ~1month/yr longer. Thus there is no pay gap once you control for hours worked.
Incidentally, the only way there could be no mean pay gap across both populations would be if no women had children. So a non-trivial paygap merely an indirect measure of the birth rate.