Galaxy and mass assembly (GAMA): the inferred mass–metallicity relation from z = 0 to 3.5 via forensic SED fitting