XnView: MP 0.99.6 - 64 bit
OS: Windows 10 20H2 / 64bit
Portrait oriented NEF and CR2 files are shown in landscape orientation when categorized
Effect: If selected a category for an image in portrait orientation the image is desplayed in landscape the the directory or filter is selected next.
To reproduce:
1. Select a directory containing NEF or CR2 images
2. Select a portrait orientated image
3. Set a category for the image
4. Select another folder
5. Re-select the folder of the categorized image
Actual behaviour (bug): The orientation of the image has changed from portait to landscape.

Expected behaviour: The image should retain is orientation (portrait).
I have investigated the issue further and the orientation is correlated with the number of category settings you do (not the number of categories set). Every other setting causes the orientation of the picture to toggle between landscape and portrait. A demonstration video can be provided (to large for upload, 4 MB).
But if you want to change the orientation without permanetly deselecting a category quickly de-select and re-select a category. This causes the orientation to flip while the selected categories are retained.
It looks as if the problem is again related to the writing of the categories to the database of XMP data. Each change of category changes the orientation, too.
This bug exists at least since version 97.1.