Android OS is released under Apache license, means you are free to edit the source code. It is NOT illegal to edit this OS from any part of the world. This license says that you are free to edit, modify and distribute but you do not sell this modified OS.
Rooting is not at all a bad term. In Linux root means you are the admin/owner for your OS. As a root user you can change the system settings and preferences as you prefer, normal user can't do this. Android is also a kind of Linux OS and follows the same principle.
Smartphone vendors lock the OS because changing the settings without proper knowledge may cause the OS to malfunction. If you have thorough knowledge about Linux and their system settings you can be the root user. Mobile manufacturers restrict user to have root access.
Learning about rooting and custom ROM increase your knowledge that how your OS works. Try to develop your own custom ROM, you can add functions whatever you like. Most of the custom ROM were released to decrease the bugs available in default Android OS. By rooting you can use the full performance of the processor. For example: If a processor have clock speed up to 1.6 GHz, mobile vendors will reduce it to 1.2 GHz for some reason. You can customize and set it to 1.6 GHz (or whichever is maximum). Mobile manufacturers won't utilize the full performance of the processor. You should edit the OS in the way to utilize the full performance of the processor.
Caution: Rooting will void warranty. If your mobile phone got bricked then mobile phone vendors won't replace your mobile. It is because you are responsible for your mistake.