There are guesses, but no one really knows for sure. It's intuitive to think that the colors and patterns of bird eggs should help provide camouflage for the eggs while they're in the nest. However, it's been problematic to show a relationship. For instance, one scientist, Gotmark, painted eggs different colors (brown, white, blue, spotted) and placed them in nests with varying degrees of cover, then kept track of which eggs suffered predation. The color didn't seem to have any relation to the predation suffered, at least not in coniferous forests with chiefly avian predators. Another theory is that birds can recognize the markings of their own eggs, or that they can recognize when brood parasites like cuckoos or cowbirds sneak an egg into their nest.
Still, there is a relationship between egg color and nest type in wild birds that suggests the difference has (or once had) to do with camouflage. White eggs are chiefly laid by cavity nesters, where the eggs will be more concealed. Grey and brown eggs are more often laid by ground nesting birds. Speckled eggs or blue eggs are often laid in open nests. There are a few exceptions, though. For instance, hummingbirds lay white eggs in an open nest, but they actually start incubating on the first day they lay an egg. (Most birds, including chickens, wait to gather a clutch, first.)
So, why do chickens lay different color eggs? The best we can tell you for sure is that they just do. To read about how the egg shell colors are made, please view the "related questions" below.