Over time, WD-40, if left in the same confined area, will (or at least can) congeal into a semi-solid, hard, waxy substance that is difficult to remove. If this hardened residue finds itself in a place where tolerances are tight for small working parts to move, it can result in a malfunctioning firearm.
Thanks to all who pointed this out. I cringe when I see someone recommending WD-40 to lubricate a gun. As others have pointed out, it's a Water Displacement formulation and works great at that job. My gunsmith, who has been working on guns since the late 50's, said he has repaired more guns that were fouled up with WD-40 than for any other reason. He showed me a trigger group from a Remington 700 that was so fouled up with WD-40 that the parts would not even move. A thorough cleaning with kerosene or Gun Scrubber, followed by a proper lubrication with a good gun oil usually fixed the problem.