Research shows that most of our decisions start with emotion; there is no guarantee the decisions will be rational, but if they satisfy the emotion magical thinking may ensue.
OCD is probably the most common form of magical thinking. The behavioral actions resolve anxiety, and the actions become necessary whether rational or not.
I've yet to find anyone, not affected by emotion, and not subject to magical thinking. However, medical conditions can cause people to lose emotion and the memory that is associated with emotion, and the subjects of that "reality" rarely function in life.
Obviously, there are degrees of magical thinking that can be harmful, but without the ability to assume B is the effect of A, there is no illusion of control, and chaos is certain.
Those that believe they have the most rational control of life, are often the ones that are subject most, to magical thinking. They can thank their behavior and resolved emotions for this illusion of control.