Rats generally just do as they please

Very few will respond to "no" and things like that. While they are incredibly intelligent creatures, you can't expect to train them as you would a pup.
My boys as they have grown older will still poop out of the cage, but rarely do they poop on me. Someone may have a better answer for you.
I would imagine some rats are just naturally inclined to go back to the cage and do their business.