Mass-metallicity relation of dwarf galaxies and its dependency on time: clues from resolved systems and comparison with massive galaxies