system
Given the following post, respond as if you're commenting on Reddit:
human
ELI5: How come you cannot carrier unlock a mobile phone without paying for a "code", even with custom firmware and root access?

Basically where do these codes come from and how do you (or the people that run websites that sell them) obtain them and why is there no way to get around using them to unlock your phone from a certain carrier?
gpt
The cellular radio is controlled by a separate processor (often called a baseband processor) with completely separate firmware.

In order to bypass the lock, you either need to get that CPU to release the lock by giving it the code it wants, or you need to somehow hack into it. 

The problem is that even if you can install custom firmware on the phone, that doesn't help. You still need somehow hack the baseband, and get it to release the lock. 

Some early versions of the iPhone could be unlocked. If you installed a custom firmware on the phone, it was possible to run an app which would take advantage of a bug in the baseband firmware, and cause it to unlock until the next reboot. However, these were often very unstable, because the app was basically trying to glitch the baseband CPU and make it malfunction. Apple rapidly fixed this by pushing out new firmware for the baseband.

The difficulty with trying to root the baseband is that it runs a much simpler OS. Complex OSs like iOS, windows and android have a lot of code, so could have lots of bugs - you just need to find a bug that gives you root. The baseband runs a very stripped down OS, because all it needs to do is handle the calls and data. This means that there are fewer possible bugs, and bugs which might allow root access or cause a malfunction are super rare (assuming that they haven't all been fixed).