The image has a rotation specified in its Exif data. The rotation is applied when opening the image by itself in a separate tab or external image viewer but not for thumbnails or inline expansion.
See issue #3692