To correctly identify if you can legally change an IMEI number you need to know the region/country you are in because laws very.
There are some techniques to change an IMEI number on a phone which may or may not be legal depending on when it is done and in almost all cases will be illegal if it is done to defraud a carrier for theft of services.
If you want an overview of what an IMEI number is you can read the Wikipedia artical.
In the US I don't believe it is technically illegal to spoof an IMEI number but it is illegal to defraud a carrier or recieve knowingly stolen goods--so if you are trying to spoof a IMEI number to make a stolen phone work or use services you have not paid for you are subject to laws related to the other illegal use.
While I may be jaded, since most carriers will allow an individual to change to compatiable hardware purchased from other sources (example used hardware) there should be few reason to spoof a IMEI number in the US. Each regions laws will differ.