The Core Mass Function across Galactic Environments. III. Massive Protoclusters