If the play was run with 12 on the field, it is a foul. The flag will come when a definitive count is made. I've seen this happen on punts a couple of times and the chains have already moved, but that's why a clip is used, so they know where they were and can reset.
Sometimes counting players is harder that one would think, if the team is substituting, the ball is on the hash in front of that bench, the formation is bunched -- all these things can make counting tough. If it's possible to definitively count 12 before the snap, it should be blown dead before the snap. This isn't always possible. Once it's snapped, the play is officiated as usual because you don't want to be mioss the flag.ssing big things because he's counting.
What should happen is that if an official(s) thinks they might have had 12 on the field, he will head to that sideline so he can make sure no one comes on or off before a count is made. If one comes off and there's still 11 out there, it's the correct time for a flag.
There are times when an official thinks a foul happened, but needs more info to be sure.