I am taking a beginning course in QM and I have learnt that the measurement of energy collapses the wavefunction of a particle to one of its energy eigenstates. But some misconceptions regarding this is leading straightaway to the violation of the Uncertainty Principle in potentials that is independent of position of the particle. Consider the most elementary case of an infinite square potential well : $$V(x) = \begin{cases} 0, & 0 < x < L,\\ \infty, & \text{otherwise} \end{cases} $$ The energy eigenstates are : $$ \psi_n(x) = \begin{cases} \sqrt{\frac{2 }{L}}\sin(\frac{n \pi x} { L}) & 0 < x < L,\\ 0, & \text{otherwise} \end{cases}$$ After, say, the measurement of energy returns a value $ E_n $, the wavefunction becomes $\psi_n(x) e^{i \frac{2 \pi E_n } {h} t}$. Shouldn't then, the particle have a definite momentum $ \sqrt{2 m E_n} $ ? The positional uncertainty is still (approximately) $ L$ and hence the Heisenberg principle seems to get violated.
P.S. : I know that the actual momentum uncertainty calculated by the routine method $$\langle p \rangle = \int_{-\infty}^{\infty} p P_n(x)\,\mathrm{d}x$$ is $$\mathrm{Var}(p)=\left(\frac{\hbar n\pi}{L}\right)^2$$. But what is wrong with the above line of reasoning ?