The legality of jailbreaking an iPhone varies depending on the country where you reside. In the United States, jailbreaking an iPhone is legal under the Digital Millennium Copyright Act (DMCA) of 2010, which grants an exemption from the anti-circumvention provisions of the copyright law for users who want to jailbreak their smartphones.
However, it's important to note that while it's legal to jailbreak an iPhone, it does come with some risks. Jailbreaking involves removing the software restrictions put in place by Apple, which can compromise the security and stability of the device. It can also void your device's warranty, and Apple can choose not to provide support for jailbroken devices.
Overall, whether to jailbreak an iPhone or not is a personal decision, but it's important to consider the potential risks and consequences before proceeding.