Due to Eddy currents heating up the metallic pieces.
Due to high frequency AC coil carrying current, there is a strong magnetic field around the coil. The metallic pieces which are sizeable, are subjected to changing magnetic flux in them. Hence, as per the Faraday's induction and Lenz's law we have emf induced in circular shaped paths. These eddy currents flow in the metal with very small resistance. Hence, even for small currents, there is a good amount of heat generated.
So the metallic pieces get hot.
When the switch is a bit loose or the spring inside the switch is not very strong and loses its action, this spark may be produced when the light is switched off.
When the switch is disconnecting the line current from neutral, due to the slowness in the action, the gap between the two separating metal pieces increases slowly and not suddenly. Hence, the gap is small enough (like about 0.1 mm to 0.5mm) for the potential (230 V) in the live wire to influence an electric discharge through air. When the electric field in air is about 10^6 V/m or more, electric sparks flow in air. Here, the electric field is about
E = 230 V / 0.5 mm = 460 000 V/m
Hence this high electric field strength in the air gap between the two slowly separating contacts of the switch, nears 10^6 V/m, the spark comes on.
However, the spark lives only for a fraction of second, so it does not cause too much of a damage.