Why are these two methods of converting from ppm to g/m3 equivalent?
Using the ideal gas law
$$
pV = nRT = \frac{m}{M}RT
$$
you can express the density $\rho = \frac m V$ in terms of molar mass, pressure, ideal gas constant, and temperature:
$$
\rho = \frac{pM}{RT}
$$
With the units you use in your second example, this yields a density in $\mathrm{g\,m^{-3}}$, whereas you insert a density in $\mathrm{kg\,m^{-3}}$ into your first equation. Thus, I will write your first equation as
$$
C[\mathrm{g\,m^{-3}}] = \frac{C[\mathrm{ppm}] \cdot \rho}{10^6}
$$
where the density is in $\mathrm{g\,m^{-3}}$.
Inserting the expression for $\rho$ derived above into this equation, we get
$$
C[\mathrm{g\,m^{-3}}] = \frac{C[\mathrm{ppm}] \cdot \rho}{10^6} = \frac{C[\mathrm{ppm}]}{10^6}\frac{pM}{RT}
$$
which is identical to your second equation.