Modern cameras, phones included, put orientation information on the photos. Sometimes all you can do is open it in a photo editing program, rotate it then re-save the correctly oriented picture, maybe with a new name. I once spent some time looking through a load of photos, rotating some as I went. When I left the photo viewing program all the ones I had rotated were back where they started because I had not saved them in the new orientation.
Martin C