Jailbreaking is not illegal in most countries, but it is against Apple's terms and conditions of use. If you jailbreak your device, you may void your warranty. The legal status of jailbreaking can change over time, so it is always best to check with your local laws before doing it.