Polynomial time verification of Graph Isomorphism problem
The choice of function is done in nondeterministic polynomial time which is something you shouldn't try to &quot;make sense of&quot; in the real world.
It is a mathematical model of computing where we assume that the machine can perform many simultaneous operations, kind of in parallel, and if any of these operations &quot;succeed&quot;, you get one of those answers out.

The point of this exercise is however that you show that Graph Isomorphism is contained in the complexity class NP by showing that you can solve the problem in nondeterministic polynomial time; by giving a nondeterministic algorithm for the problem.
The algorithm works as follows.  Nondeterministically pick the correct permutation $\pi$, and then in deterministic polynomial time we can verify that $\pi$ is indeed a witness or a certificate for the fact that the two input graphs are isomorphic, by checking that $\pi(v)\pi(u) \in E'$ if and only if $uv \in E$.
If $\pi$ is not a permutation that proves that the graphs are isomorphic, you can therefore conclude that the graphs are indeed not isomorphic.

It is important to stress that this does not give rise to an algorithm you can actually implement  in the real physical world, not without enumerating every permutation, at least, which as you correctly point out, cannot be done in polynomial time.