WD 40, when used as a lubricant on something originally lubricated with grease, CAN remove the oil from the grease, leaving behind the "soap" (sodium stearate in some cases, lithium in others, plus a host of others)- which will cause mechanisms to stick.
As for electrical contacts - on sliding contacts like many automotive switches, and at low voltage and current, not likely to cause much problem - but any arcing in a switch with "oily" contacts WILL cause carbon build-up - which CAN cause high resistance, heating, and burning of contacts. High voltage and high current contacts must be CLEAN or lubricated/protected by an inert grease (dialectric grease) that will not burn and protects against corrosion.
Spray WD-40 (aerosol) has (or at least had) a flammable propellant, which, if used on an arcing contact - or in proximity to an arcing contact, CAN ignite - with rather spectacular result if, say, inside a distributor cap.
There are NO manufacturers that plackard their under-hood areas with prohibition against using WD40 under the hood. It is EXCELLENT for drying out damp ignition wires - even though there are better products, which help seal the wires against moisture for a longer time - but NEVER use "ignition sealer" - the plasticy coating if compromised at all, just traps moisture in the wire, making it worse - and impossible to dry out with WD-40 or anything else.