Nag is another word for a horse. When someone is nagging, they are complaining. So this joke is using the word nagged as a way to complain about someone who is riding a horse when someone wants them not to.
' ' I told you not to ride that horse , ' ' Tom nagged .