If you have a cat you probably don't even remember what it's like to pee by yourself. Your cat will somehow weasel its way into the bathroom because God forbid he or she is left alone for 30 seconds while you relieve yourself.
Cats don't strictly follow you to the bathroom, they'll follow you all over. But for some reason the bathroom is like an enchanted forest to them. Once that door starts to close, cats cannot and will not stay out of the room.
But why is that? Why do cats feel the extreme need to watch you pee? It's gotta be their extreme FOMO (fear of missing out).
Some people believe that because cats have a toddler-like mentality, they just don't want to be left without you. Especially if you're doing something behind closed doors. If they can't see you, they're not happy.
It could also be that cats just like the cold bathroom tiles and want to enjoy them while you do. Since you're not usually in there, they probably forget the tiles are an option and then you trigger their memory.
Another, and the most likely reason, is that cats just don't like being ignored. So if that means they have to follow you to the bathroom then they will. As for why they want to sit in your pants while you pee, that's just because they're cats. There's no real explanation.