I think what is generally happening with Pain Split is that AI sees it as a damaging move. When you are at low health, I believe the AI is programmed to use a weaker attack to KO a pokemon to preserve PP for the stronger attacks that are needed to KO the next thing coming in. What attack is weaker than a 0 BP attack to finish off a weakened opponent?
I kind of noticed this in the second battle against Lusamine. Her Mismagius, who was a pain to take out in the first battle thanks to Mystical Fire not letting my special attackers do their part (and my physical attackers being all weak to Ghost), did nothing but spam Pain Split.
Of course, as best I can tell, AI uses Z Crystals completely randomly, which is why it can use Z moves to try to finish off a weakened opponent like Codra's example.
Or use it on a Mimikyu that still had its Disguise up like in my example.