Talk about fooling most of the people most of the time! Of course, superstition is actually a well-known phenomenon in the animal world. Experiments with rats have shown that if you give them a reward (say, food), shortly after they accidentally bumped their shoulder against a wall of their cage, they will start purposely bumping against the wall, expecting a new reward. This is no different from human beings associating a win by their favorite team to them wearing a “lucky” shirt or hat. Both are examples of a widespread logical fallacy, post hoc ergo propter hoc (after that, therefore because of that), where a causal link between two events is inferred on the basis of an observed correlation. The difference between rats and humans is that the former give up their illogical behavior much sooner than the latter, if no further reward is coming. (Of course, what makes the elevator such a machiavellian device is that the reward does keep coming!)
More generally, superstition (and therefore religious belief, which is a form of superstition) can likely be traced back to two factors, one of which seems to apply only to humans (and perhaps other closely related primates). The first factor is exemplified in the widespread use of observational correlations in the animal kingdom: it simply makes sense for natural selection to favor the ability to uncover potentially significant patterns in the environment, so that the organism can take advantage of them. However, one would also expect selection to favor the quick abandonment of pattern-based behavior if the pattern turns out not to be a reliable clue for action -- exactly what happens with rats.
The second factor applies only to animals with a sufficient sense of self that they develop a need to be consciously in control of their lives: human beings first and foremost. This need for control is in fact so strong that we project agency onto the natural world and invent gods so that we can then pray to elicit favors from them. Or we keep pushing the elevator button even though it doesn’t do anything, smiling with a satisfied smugness once the doors finally do close -- even if they would have done so regardless of our pointless actions.