Commonly happens when you reuse trainer data between games. Trainer name/ID should be unique, not the same (eg Sword and Scarlet should be different).
If it has a handling trainer set and the current handler is the HT, then the HT must match the save file.
If it matches the trainer data for the save file, then it should be handled by the OT, not the HT.