The original routine forces the opposing trainer to inherit the player's backsprite palette. Karatekid's fix replaces a 'swi 0xB' with mov r8, r8 to fix this issue. But then I was getting an issue that caused the player's backsprite to inherit the default hero's palette on every frame except the first one. Removing the trainer palette fix resolves this issue, so my routine just checks the frame number; if the first frame is loaded, it applies the trainer palette fix. For all other frames, it performs the original routine without the trainer palette fix.
I would play around with the original routines and each fix to try and isolate what is causing the HP bars to change. It's strange that I'm not getting the same error.. :/
edit: these issues only come about for trainer battles. Does the same problem happen during those? If not, we could add a battle flag check to keep the original routine if you're in a wild battle.