I believe this can be a bug in the sensor data. I've seen it happen before (though it's rare).
I haven't been able to reproduce this bug reliably, but I have a theory. Perhaps when you pressed the camera button, you subtly (but with just enough force) jerked the phone in the horizontal direction. This sudden movement could theoretically be picked up as meaning the phone is oriented in landscape mode. Or, perhaps it took the photo at just the right point where noise in the data right at that time was interpreted as the phone being in landscape orientation. If this is the reason it's happening, you can fix the photo by using one of the several photo editing apps in the Marketplace. Just rotate it to the correct orientation.
However, it is good to note that if you are taking a photo with the phone relatively flat (say, you are pointing at something on a desk or table), landscape or portrait orientation is not something the phone can deduce as you aren't standing vertical. Since orientation is sensed by which way is "down" through the accelerometers, if you are pointing "down", it will just use the best guess. That means if you're pointing down and have the phone tilted to one side, it will use that tilt to guess orientation. Pay attention to the Camera app UI controls and make sure to hold up the phone in landscape mode before pointing it downward, while being careful not to tilt it to either side in the process, and it won't accidentally switch to portrait mode.