Apple is not in favor of jailbreaking, for a variety of reasons, and it violates the user agreement that you accept when you first use your iPhone.
But, jailbreaking is NOT illegal. Apple cannot send out the "jailbreak" police, and take you to jail, and it's highly unlikely that Apple would ever sue an individual user, and take you to court, just because you installed some unusual software.
But, I think you have the wrong idea. Jailbreaking does not provide a way for you to download commercial apps (for free) from the App Store.
You would continue to have normal access to the App Store, but you would still need to purchase commercial apps.
Jailbreaking does allow you to download and install apps from other sources - outside of the App Store, plus jailbreaking allows you to configure and use your iPhone in ways that iOS does not offer, and you can change the iPhone's appearance significantly.
But, you still have to pay for commercial apps from the App Store.