It's not a euphemism for a hangover, more a cure. The idea is that like cures like - a principle adopted in vaccinations, where a controlled dose of the virus is injected into the system to allow your body to develop antibodies. So the best cure for a hangover is to have another drink. Doesn't always work for me, though.
It's - like a lot of phrases - from Shakespeare, Julius Caesar I think. "Find me the hair of the dog that bit me last night" says one of the characters after a waking up with a hangover.
The famous cure for a hangover is named 'the hair of the dog' this saying developed from an activity in medieval times and was supposed to be a cure for a bite from a mad dog. The belief was that if the person who was bitten by a mad dog, either ate some of that dogs hairs with a slice of bread and some rosemary, they would be protected. Another version was to bind the wound with some hairs from the dog and some herbs to gain the protection.