I was under the impression my video on the subject matter covered it well, but here's a TLDR.
The Pokemon's PiD is set when it is first faced and the game says it is a shadow. If, at that point, you capture it or simply defeat the trainer, then the PiD is permanently retained for the next time you face the trainer. The AI's TiD/SiD combination is always randomized. As such it is entirely possible for a Pokemon to be a shiny or even nonshiny for a given AI trainer.
May as well clarify on the following points while we're at it: The moment you capture a Pokemon, its shininess for you is determined. The "???" on the OT name/ID is merely an aesthetics thing, the actual IDs are yours if you were to look in the RAM. Another common misconception is that purification takes away or even gives shininess. That is also false.
In conclusion it is possible for the same shadow Pokemon to be shiny and nonshiny on the same AI trainer, and it is also possible for it to be shiny for you but not the AI, and vice versa. My video that Slayer posted on the subject matter covers such scenarios.