I dimly remember problems with P1SELC. There was a thread about it quite some time ago.
In the code you posted, I don't see anything suspicious. And the failure doesn't happen at startup (init). So if there is a code-related problem, then it is in the project-specific code.
Maybe an ESD event triggers a port pin interrupt that your code is not expecting in this situation, so it behaves undefined. I can't do much more than just guessing, sorry.