Although each illusion has it's own reason, and scientists still don't know all the reasons, it comes down to one thing. Our brain makes assumptions.
Our brain uses context of our surroundings to make split second assumptions. This is helpful in everyday life and back when we were hunters and gatherers and needed to make split second decisions in the wild. Our eyes don't show us what's really there just what we need to see. It uses the surrounding environment to make conclusions. This is done by using shadows, surrounding colors, and past experiences.
optical illusions are just a case of your brain telling you what you should be seeing, not what is actually there.