They are paid ether by their respective universities/institutions/companies and/or they pay themselves from the grant money they were awarded for a specific project.
But the key point is that they're not paid by the publisher for the publication, they're paid to produce the publication by others. The publisher is just gets it for (basically) free and then profits off the fees.