Momentum Wave Function gives strange expectation values 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$
Desmos graphs of related curves
 A: The question has evolved a bit, so I've included some corresponding revisions to the answer here.  The original question was about an inconsistency in the result for computing $\langle p^2 \rangle$ two different ways and getting different answers each way.  Now you seem to be computing consistently but don't think the answer is correct.
Your original position-space wavefunction, where you put in a piecewise constant function, does not obey the Schrodinger equation at $x=0$ or $x=L$. It's hard to see how anything after that is meaningful if you proceed directly from that.
If we ignore that and just pretend it's ok for a second to think through the formal portions of the error, your claim that the first derivative $\partial_x \psi = 0$ is false at exactly the points that I mentioned. At those points it's undefined / infinite depending on your level of rigor.  You are inevitably seeing a consequence of this inconsistency when you try to analyze the quantity via the (smooth) Fourier transform that you've provided. (I didn't check that the Fourier transform is correct.)
Following comments, you went on to consider a superposition of particle-in-a-box solutions that approximate the step function. That's legitimate.  As I understand it, you're now finding that $\langle p^2 \rangle$ diverges and, I gather, thinking that somehow violates that uncertainty principle.
First, I didn't compute it myself, but I won't be shocked if the expectation value that you're computing does diverge.  You've now done it yourself two different ways and found that answer.  To approximate the spatial wavefunction that you've given you need to include higher and higher energies in your superposition albeit at lower and lower weight in the sum.  That certainly could lead to a divergence for what you're computing.
Second, I don't understand your apparent concern about this and the uncertainty principle.  The uncertainty principle gives you a bound, but there is nothing that says that every solution will be tight to the bound.  Unless I've misunderstood your point, I don't see a violation of the uncertainty principle here.
