Ok, I try to explain it again since this nonsense of momentum operators for particles in a finite box come up often, including the homework section. Is there any serious textbook, where they claim a momentum operator exists for a particle in a box? I hope not!
Let's work in the position representation, i.e., with the wave-mechanical formulation of non-relativistic quantum mechanics. The Hilbert space is then the set of square-integrable functions \mathrm{L}^2([0,L]) with boundary conditions \psi(x=0)=\psi(x=L)=0.
By definition the momentum operator is the generator for translations. This is related to Noether's theorem identifying momentum as the conserved quantity that follows from spatial translation invariance. This implies that in position representation the momentum operator is given by
\hat{p}=-\mathrm{i} \partial_x.
Suppose now, this is a self-adjoint operator in our Hilbert space. Then there must exist a complete set of generalized eigenvectors in this Hilbert space. This implies
-\mathrm{i} u_p(x)=p u_p(x) \; \Rightarrow \; u_p(x)=A \exp(\mathrm{i} p x).
Now, the eigenfunction must fulfill the boundary conditions, leading to A=0, i.e., there doesn't exist any eigenfunction for the momentum operator, and thus this operator cannot be a self-adjoint operator and thus it doesn't exist as an observable for the particle in a box.
That's, of course, different for the Hamiltonian, which is given by
\hat{H}=-\frac{1}{2m} \partial_x^2.
The eigen-value problem becomes
\partial_x^2 u_E(x)=-2 m E u_E(x) \; \Rightarrow \; u_E(x)=A \cos(\omega_E x)+B \sin(\omega_E x) \quad \text{with} \quad \omega_E=\sqrt{2 m E}.
The boundary conditions then lead to
A=0, \quad \omega_E \in \frac{\pi}{L} \mathbb{N}.
These are nice functions in the Hilbert space with eigenvalues
E_n=\frac{\pi^2 n^2}{2m L^2}, \quad n \in \mathbb{N}.
The corresponding eigenfunctions are
u_n(x)=N \sin \left (\frac{n \pi x}{L} \right ).
The normalization constant is fixed by
\int_0^L \mathrm{d}x |u_n(x)|^2=1 \; Rightarrow \; N=\sqrt{\frac{2}{L}}.
As it is well known that these sine functions build a complete set on the Hilbert space under consideration, the Hamiltonian is indeed a self-adjoint operator and thus represents a proper observable.
Indeed, everything changes if you look at the "rigid rotator", where instead of "rigid boundary conditions" you have "periodic boundary conditions". There the translation operator is a proper self-adjoint operator, representing angular momentum.