The CP of a Pokemon that is caught right after a raid is determined at the start of the battle. This is because we all need some background information. And when the game crashes on the catch screen following a raid, often the Pokemon that should be caught will have a different CP than it did before the crash.
We can inform you that this is a visual glitch, it does not affect the actual CP. But, this glitch is not random. In every raid, there is exactly one CP value that is on the privileged side. The following example has been tested by DH025 on Reddit and it is not hypothetical:
Two Trainers fight a Machamp. Trainer 1 gets a CP of 908. Trainer 2 gets a CP of 874. Both of the Trainers then have an app crash while trying to catch the Pokemon, and both after that reload the app. When re-entering the catch screen, two things have to happen. The CP on both screens will be identical. According to this, both of the CPs will be either 908 or 874, depending which number has the privileged value. If you do a solo raid, and receive a CP of 908, crash on the catch screen and then reload the app, your Pokemon will still have a CP of 908. This is because your CP is the only one available.
We still do not know why one Trainer’s CP value is chosen. All we know is that this is happening all the time. This glitch also shows that the CP values of all Trainers are somehow connected in some way. We have a theory of how this glitch can help to prove that CP values are determined at the start of the raid battle.
Let’s imagine that two Trainers are on a Machamp raid again, but Trainer 2 quits in the middle of the battle. Trainer 1 finishes the raid and receives a CP of 1598. This same Trainer then crashes on the catch screen and reloads the game. When re-entering the Trainer sees that the CP has changed to 1604. This means that the CP that Trainer 2 had was 1604. We know this because the system selects one CP that is considered as privileged, so it must’ve come from Trainer 2.
So if the CP is determined during a raid battle, that must be at the very start of the battle. And another thing: CP is not determined at the lobby.
Let’s suppose that many players join a raid lobby. Now, all players but one back out of the battle. The remaining player will do a solo raid, and then crashes on catch screen and then reloads. In every case where we have done this, the CP does not change. Of all CP values to choose from, only one is available. This explains why there is never a change on the catch screen. If only one player is present during the raid battle, the raid is done by only one player, regardless of how many Trainers were in the lobby. Changes in the lobby do not affect the CP.
To sum this all up, the pool of CP values, and all CP values are determined when the raid battle begins. Not before, and also not after the raid battle.