The role of the cosmic web in the scatter of the galaxy stellar mass–gas metallicity relation