In my experience this mainly occurs with JPEG images. Converting the correctly rotated version to PNG beforehand with any respectable image editor or converter should resolve this issue (that is, if you don't mind the image size increasing). PNG does technically support this metadata as of 2017, but it's not nearly used as commonly as with JPEG.
It might be that your phone camera actually takes them like that, but shows them to you rightside up. When you upload an image, you're uploading the exact file of the photo. If that file is "sideways," it's going to be sideways on Lemmy.
I'm wondering how much of this is the gallery software on the phone maintaining its own metadata database rather than writing that info to the file using any of the industry recognized formats (EXIF, IPTC, XMP). I've been building a library of old family photos, and the number of apps that do this is shocking. Most, if not all, don't even have a mechanism to write it to the photo or even export the MD to a file. I had to look around to find a good library app that actually managed the photo metadata properly, and that wasn't Lightroom (because screw Adobe and their greedy subscription model)!
FWIW, I'm on Mac, and am liking MetaImage & NeoFinder.