Voltage spike when switching relay on

Hi,
I am using the relay on the automation hat mini to switch a solenoid. Out of curiosity i measured the switching event with a scope and noticed a damped oscillation after switching 24 V on with the relay. The oscillation peaks at almost 40 V. Notice: I would expect a spike when switching the solenoid off, but this happens when switching it on. Further this happens as well when i do not connect the solenoid and just measure the open-circuit voltage. What causes this spike? And what can i do against it?

Perfectly normal event when switching inductive loads on and off.
You will need to put a back EMF diode across the solenoid coil and possibly a capacitor across the relay contact to suppress arcing.
For further info simply Google “inductive switching” for reasons and protections for this phenomena.
Note the on-board relay coil itself will also do this and if you check it’s circuit diagram you may find the protective diode across its coil to protect the switching transistor/mosfet driver.