Medieval castles had a room known as the Garderobe which translates as wardrobe. The room was used for hanging clothes and as a latrine the smell from which apparently kept cloth eating bugs away. The exit from the latrine, which you can see in this picture at Portchester Castle, would have drained into the moat.