As reported the EFF has won some major exceptions from the Digital Millennium Copyright Act (DMCA) for consumers. One of them is that you can jailbreak your iPhone and not violate the DMCA.
Cult of Mac has pinged the Apple PR department about the decision. The response included that you risk voiding your warranty when you jailbreak your iPhone to run unauthorized apps.
Apple is an advocate of a controlled experience. Jailbreaking the iPhone circumvents their controls. Apple is right to be against jailbreaking, because if it would be common practice the genius bar would be full of customers complaining about their iPhone experience.
You should only jailbreak your iPhone if you know what you are doing.
By the way unlocking is not legal.