I've heard people say it's because it simulates a smile. But when I say cheese, all that happens is my bottom jaw juts out and I get a food woodrow.
The origins are lost in the annals of Time's ass, I'm afraid.
Here's some interesting shit. They say different words in different places.
In Argentina, they say 'whiskey'.
In Bulgaria, they say, 'cabbage'.
In China, they say 'eggplant'.
In Denmark, they say, 'orange'.
In France, they say, 'marmoset'.
In Korea, they say, 'kimchi'.
In Spain, they say, 'potato'.
In Sweden, they say, 'omelette'.
In my house, they say, 'Keith! Get your fingers away from your crotch!'
They know where that can lead.
Short Answer: I've also ruined a few Christmas cards with some pretty deep knee bends and significant, kilted squats.
Note: I got this shit from Wikipedia (except for the crotch-fingering part). At the bottom, under See Also, it read: Cheese, the food to which this phrase refers. I thought that was fucking funny.