The VANDELS survey: The stellar metallicities of star-forming galaxies at 2.5 < z < 5.0