After Nagato loses Yahiko in Naruto Shippuden, he changes his name to Pain and pursues his goal of inflicting pain and suffering throughout the shinobi world. His name reflects his philosophy, and he believes he's found a foolproof way to establish peace. Pain is an extremely compelling character because though he's a villain, he isn't entirely wrong.
Source:https://www.cbr.com/naruto-best-nagato-pain-quotes/