The evolution of the mass-metallicity relation and its scatter in IllustrisTNG