Well, we can tell you HOW the different colors are made, but there really isn't a good answer as to WHY the different colors are produced. (To read about how the egg shell colors are made, please view the "related questions" below.)
As to why, no one really knows. There are a few guesses. 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. Similar experiments testing the effectiveness of egg crypsis have been repeated a few times with similar results
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.