This is a really weird problem, so I'll try to explain this as best as I can. Below, I have created a script that'll change the Pokemon in slot one to a Phanpy.
After running the script, all the Pokemon are changed to Phanpy, but all the Pokemon have an illegal mark on all of them. I selected one of the Phanpys and clicked the illegal mark to find out what's wrong, it changes to Legal and shows the checkmark. I thought it was just PKHeX being buggy, so I left it. I injected all the changed Pokemon into my game and tried to wonder trade. For all of them, it showed "There is a problem with this Pokemon".
I go back into PKHeX and select a Phanpy, click the illegal mark so it'll show as "Legal" then replace that Phanpy with the Phanpy that is being marked as illegal. I inject that Phanpy into game and it goes through wonder trade with no problems.
=Box=1
.Species=231
.IsNicknamed=True
.IsNicknamed=False
.IsNicknamed=True
.IsNicknamed=False
.Nature=3
.Ball=5
.Move1=583
.Move2=68
.Move3=420
.Move4=34
.RelearnMoves=$suggest
How to replicate problem:
1. Download .pk7 file : 546 - Cottonee - 204764F52F21.pk7
2. Place Cottonee in box 1
3. Run the script
4. The cottonee will change into Phanpy, but with an illegal mark on it. Inject this phanpy into game and the game should not allow you to trade it.
5. Do steps 1-3 again, but select the Phanpy, and click the "illegal sign", and it should say it's legal, and the symbol should change to a checkmark. Alternatively, replacing the selected Phanpy in the box again will remove the illegal mark
6. Try wonder trading phanpy and it'll go through
Thanks in advance to anyone who can help me.