We report a combination of Fe Kβ x-ray emission spectroscopy and density functional reduced Stoner theory calculations to investigate the correlation between structural and magnetic degrees of freedom in CaFe2(As1-xPx)2. The puzzling temperature behavior of the local moment found in rare earth-doped CaFe2As2 [H. Gretarsson et al., Phys. Rev. Lett. 110, 047003 (2013)] is also observed in CaFe2(As1-xPx)2. We explain this phenomenon based on first-principles calculations with scaled magnetic interaction. One scaling parameter is sufficient to describe quantitatively the magnetic moments in both CaFe2(As1-xPx)2 (x=0.055) and Ca0.78La0.22Fe2As2 at all temperatures. The anomalous growth of the local moments with increasing temperature can be understood from the observed large thermal expansion of the c-axis lattice parameter combined with strong magnetoelastic coupling. These effects originate from the strong tendency to form As-As dimers across the Ca layer in the CaFe2As2 family of materials. Our results emphasize the dual local-itinerant character of magnetism in Fe pnictides.