How should I reconnect the wires if they slipped out of the rear light?

All Herrmans dynamo and e-bike rear lights are equipped with a rectifier, so you don’t need to pay attention to the polarity of the cables.