Evolution of the Mass–Metallicity Relation from Redshift z ≈ 8 to the Local Universe