When casting a spell, do you select targets at the time of casting the spell or when the spell's effects take place?
For an example of when the distinction might matter, consider casting a single-target spell like hold monster with 3 potential targets available. As a reaction to the casting, one of the targets attempts to cast a spell like counterspell (and it fails to interrupt your spellcasting). Hold monster's effect then occurs, and since you now know one of the 3 targets is a spellcaster, you choose them specifically as the target. (Or you're stuck with the original choice you had in mind, if targeting is done at casting time.)
I'm under the impression that targeting (at least for a spell described like hold monster is) is part of the effect, so you choose targets after the process of casting the spell has successfully resolved. Assuming that your game treats counterspell as being cast during the process of casting, it seems like you would have the knowledge of one of the enemies being a spellcaster when resolving the uninterrupted hold monster's effect.
The reason I have the impression of targeting being part of a spell's effect is that the rules for casting a spell indicate that all text that's not part of a spell's basic information is part of a spell's effect:
Each spell description begins with a block of information, including the spell's name, level, school of magic, casting time, range, components, and duration. The rest of a spell entry describes the spell's effect.
And then for spells like hold monster, it's the spell's effect text that tells you to choose a target:
Choose a creature that you can see within range. The target must succeed on a Wisdom saving throw or be paralyzed for the duration. [...]
Are there other rules elsewhere contradict this and state targeting is done at casting time?