"RATTING" is not in itself illegal.
Using the information you get after you RAT someone is. If you steal money from, steal information from, or use anything you find against them or for profit or gain. Then you can get in a lot of trouble. The act of infecting someone in and of itself is not illegal though.
Team Viewer does just about anything a RAT can do. The only difference is you have to have their permission to do what you want/need to do through Team Viewer. RATs are more tools used to help people and companies maintain their services and machines. Putty is a program that you use with servers, as well as many other things like Putty, these are technically all RATs but they are legal and we call them programs and software rather then an underground or black hat term that was coined over the ages.
Anyway, hope this helps you understand more about RATs. Also, they are Remote Administration Tools or at least that is what "RAT" stands for. There are MANY MANY forms of RATs and there are many illegal as well as legal uses for them. So to RAT someone is not illegal, but using what you find/get from them can be.
Have an awesome day! 🤝