The piece with the wires contains a reed switch that moves in response to the presence or absence of a magnetic field.
The other piece without the wires contains a magnet, so it can activate the reed switch when the two pieces are close to each other.