Jailbreaking & unlocking both involve hacking the phone, though unlocking is a much more in-depth change to the system than jailbreaking, and you’re more likely to damage a phone this way. That’s not to say jailbreaking is safe, because it, too, can damage your phone if not done correctly.
Regardless, you are risking your own warranty if you decide to do either of these to an iPhone. If you try to have Apple repair a phone that has been hacked, they will refuse to service it and void your warranty on the spot.