I don't recognize a problem with SPI2 setup in more recent CCS C V5 versions. Either there's a bug in V5.008 or you have an issue in your hardware design or code, e.g. overwriting TRISD after initial setup. I would check the actual SFR values in hardware debugger or simulator.