As I understand it, WD-40 is primarily a mineral oil. WD-40, of course, is more than just mineral oil, but it is arguably NOT marketed as or intended to be a primary firearm lubricant -- and people who use it that way are using it to do something the company does not recommend or advertise.
Mineral oil is a byproduct when petroleum is distilled/refined to make gasoline. It is basically a residue, and has a waxy nature that is a paraffin. Wikipedia says, "some people may refer to mineral oil as melted wax, because the substance obtained when melting paraffin wax is basically the same as mineral oil." As WD-40 says in it's advertising: it's still there when you can't see it, and it fills cracks and crevices.
WD-40 was originally developed to be a very light lubricant and -- most importantly -- to prevent corrosion (on missile fuel tanks.) It does displace water, which is probably part of it's rust-resisting nature. If you go to the WD-40 site, you won't see any mention of firearms applications. You get the impression, reading their materials, that it's primary purpose in life is to prevent corrosion.
When used in a weapon as a lubricant, it can
build up and become gummy or sticky, but that doesn't mean it WILL build up, etc. Some folks swear by it, others swear at it. It's great for squeaky hinges for car and house doors, and for a quick lube of lawnmower wheels.
Go to the WD-40 site and read. It's interesting: http://wd40.com/faqs/#a91