In medieval times, Valencia was surrounded by a wall. This is one of the two gates which are still preserved.
As a curiosity, if you are important enough to be given the Keys of the City, it's the key to this gate you receive. And yes, it's a working key and you could open and close the gate with it.