We use the IllustrisTNG cosmological hydrodynamical simulation to study the evolution of star formation rate (SFR)-density relation over cosmic time. We construct several samples of galaxies at different redshifts from z = 2.0 to z = 0.0, which have the same comoving number density. The SFR of galaxies decreases with local density at z = 0.0, but its dependence on local density becomes weaker with redshift. At z ？ 1.0, the SFR of galaxies increases with local density (reversal of the SFR-density relation), and its dependence becomes stronger with redshift. This change of SFR-density relation with redshift still remains even when fixing the stellar masses of galaxies. The dependence of SFR on the distance to a galaxy cluster also shows a change with redshift in a way similar to the case based on local density, but the reversal happens at a higher redshift, z ？ 1.5, in clusters. On the other hand, the molecular gas fraction always decreases with local density regardless of redshift at z = 0.0-2.0 even though the dependence becomes weaker when we fix the stellar mass. Our study demonstrates that the observed reversal of the SFR-density relation at z ？ 1.0 can be successfully reproduced in cosmological simulations. Our results are consistent with the idea that massive, star-forming galaxies are strongly clustered at high redshifts, forming larger structures. These galaxies then consume their gas faster than those in low-density regions through frequent interactions with other galaxies, ending up being quiescent in the local universe.