Well... MetroPCS won't activate a Sprint ESN, so the method by which you get the phone eligible to be on MetroPCS is what's illegal.
Sprint and MetroPCS have an agreement that they will not activate the other providers devices (an ESN blacklist). This agreement is not contractual but more of an "Gentleman's Agreement" and is not legally enforceable. It really depends on who you talk to as to whether they will activate it or not.
The reason why a Sprint phone won't work on MetroPCS is a PRL and proxy server issue. What the MetroPCS roms do is have MetroPCS proxy server addresses and settings and in some cases the MertoPCS PRL instead of Sprint's. Not all of the phone's features may work as MetroPCS may not provide the same services and the rom may not have MertoPCS specific apps. Seeing that ESN and other FCC required identifiers remain unchanged the carrier change is not a criminal matter but a civil matter and is ,at worst, grounds for an ETF fee but in no way is it illegal.