I will appologize in advance for possibly not knowing what you are asking. Let me try this, though:
For a 1-D single particle, consider H = f(X,P). That is to say, the Hamiltonian is formed by combining the position and momentum operators in some way.
For a free particle, H = g(P). That is to say, the Hamiltonian does not depend on X, only on P. Now, P commutes with itself, so P commutes with g(P), and, therefore, [P,H] = [P,g(P)] = 0 for a free particle.
For a particle in a well, you have H = g(P) + V(X). That is to say, the Hamiltonian depends on both X and P. Now, P does not commute with X, so P does not commute with V(X), and, therefore, [P,H] = [P,(g(P) + V(X))] = [P,g(P)] + [P,V(X)] = 0 + [P,V(X)] /= 0.
Something I just noticed after rereading your post:
I think you may be biasing yourself to the x-basis. Don't think of this in terms of a basis, think of it in terms of the entire space. If you just limit yourself to the range of x-values inside the well, that is like limiting yourself to consider only certain components of a vector when you consider the eigenvalue problem. This is a bad thing to do because, when you consider the same eigenvalue problem in a generally different basis, those particular components no longer have any meaning.