Of course it's illegal, no matter if the phone is yours or someone else's.
It's an illegal act if you change the IMEI to a value which is not stored in the OTP.