Over the past few days I've been gathering some Pokémon to build a living dex for HOME. To make it easier I've looking through the save files of some of my cartridges to help with the process. A few of the playthroughs are well over 10 years old and some mons I needed had ridiculous nicknames, which I wanted to remove. I was previously convinced that once you nicknamed a Pokémon, the nickname flag that shows in PKHeX stays there forever even if you revert to species name. For that reason I nicknamed them all in lower case for gens 3 and 4 (even though species names are supposed to be in all caps for those generations).
I got curious about what would happen if I did otherwise, so I decided to check and rename a nicknamed Riolu to RIOLU in Platinum. PKHeX showed that the nickname flag was gone. I tried then to evolve it and the name got updated to LUCARIO correctly. I tried to do the same with another Pokémon in Emerald with the same result. However, if I try to manually set the nicknamed flag to on when the nickname matches the species name in PKHeX, it still shows as legal even though I can't figure out how a situation like this could happen during regular gameplay.
I read on another post regarding gen 3 that there isn't a really an IsNicknamed flag that gets saved into the Pokémon's data. If that is the case, how is PKHeX is able to figure out the flag is still on after I export and reload the save? Does it have to do with nickname trash bytes perhaps? I'm not sure.