Called the "checker shadow illusion," the effect has to do with the way our brains interpret color and shadow.
As Slate explained, "your brain is always comparing things." Square A is surrounded by lighter squares, making it appear darker, while Square B is surrounded by darker squares, making it look lighter. The shadow also "messes with your perception" and "amplifies the effect," Slate added.
If you're still not convinced, open the image in Photoshop, use the Dropper or Color Picker tool to select the color in Square A, and draw a straight line to Square B (or vice versa).