The WD in WD-40 stands for "water displacer." It makes water go somewhere else. Secondarily, it is a solvent, and it's great for dissolving glues, like the glue used to affix government-issued tax licenses to automobiles. It's not really a lubricant, but in a pinch it can temporarily function as one.
I like Swiss army knives, but they collect lint and gunk from my pockets. I use WD-40 to dissolve gunk, and to drive out water after an ultrasonic bath, but I lubricate with the light machine oil used for barber's clippers.
> It's not really a lubricant, but in a pinch it can temporarily function as one.
That's wrong. WD-40 is a literally a lubricant mixed with a solvent that makes it very fluid so it can enter small interstices, the solvent then evaporates quickly, leaving the lubricant in place.
There's not a lot of lubricant in there compared to a pure lubricant, because the solvent takes a significant share of the volume, but it's still a lubricant once the solvent dries up.
It is a blend of oils. Light oils evaporate (like kerosene does for example), and dissolve thicker oils and grease. Oils displace water in general and once in the surface pores they prevent water from getting in there again, a mixture containing light oils flows in easier and does that better. Being predominantly a light oil it is a poor lubricant, but it is better than nothing, and can flow in crevices where thicker stuff would not.
It is really simple and there is no magic.
The name took off as a brand and completely different stuff from the 40th iteration of a Water Displacer formulation is being sold under it as well.