Is there a way to prevent it?
The "correct" orientation for the camera is to have the home button in your right hand, and the ear-hole side in your left hand. Any other orientation will generate a picture that is rotated (the same as if you took a photo with your digital camera holding it sideways or upside down)
The iphone knows what orientation it was in when you snapped the photo, and if its not right side up, it adds the orientation to the jpeg meta data in the photo. It will auto-rotate any images to display "right side up" when displayed on the phone, but not all other software/devices will do that.
Either
* remember to hold the camera the right way so you don't take rotated photos or
* see if the problem software/device has an "automatic rotate" feature or
* import/rotate/export your photos in some photo editing software.