Suppose there's a particle with the wave function $\psi(x)=\frac{1}{\sqrt{L}}$ for $0<x <L$ and 0 everywhere else.
One way to get the associated Momentum Wave function is direct integration on $1/\sqrt{L}$.
$$\phi(k)=\frac{2e^{ikL/2}\sin{kL/2}}{k\sqrt{2\pi L}}$$
The first x derivative of the space wave function is zero so I'm thinking that makes the momentum expectation value zero. That's consistent with the expectation value calculated using the momentum wave function. It becomes necessary to integrate an anti-symmetric function over a symmetric interval.
Things break down for the expectation value for the expectation value of the square of the momentum. The second derivative of the spatial wave function is zero.
The integral you need to find the expectation value of the square of the momentum in momentum space is
$$ \int_{-\infty}^\infty \frac{4\sin^2({kL/2})}{2\pi L}dk$$
This integral does not converge.
Why do the wave functions give different expectation values fro $p^2$?
To be consistent with the Shrodinger Equation its better to approximate the wave function with solutions of the Particle in a Box:
$$\psi(x)= \frac{1}{\sqrt{L}}=\sum_{k=0}^{\infty}\frac{4}{\pi\sqrt{L}(2k+1)} \sin\left({\frac{(2k+1)\pi x}{L}}\right)$$
The second derivative of $\psi(x)$ times $\psi(x)$ leads to a diverging integral, consistent with the divergence found using the momentum wave function directly.
Fourier Transform of Combo PIB wave functions:
$$\phi(k)=\sqrt{\frac{32L}{\pi}}\cos{\left(\frac{kL}{2}\right)}\sum_{n=0}^\infty\frac{\cos{\left(\frac{kL}{2}\right)}-i\sin{\left(\frac{kL}{2}\right)}}{n^2\pi^2-k^2L^2}$$
It appears the divergence in the uncertainty of momentum persists despite there being finite,non-zero uncertainty in position.
Why is there infinite uncertainty in momentum instead of being on the order of $\hbar/L$
Note the curve represented by $y_8$ is what has to be integrated to get $\langle k^2\rangle$