No one would mind if their dogs only humped other dogs at the appropriate mating times. It's how they reproduce, and if their level of discretion leaves something to be desired, well, dogs will be dogs. But some dogs aren't very selective about the objects of their affections. They'll try to hump arms, legs, teddy bears, sometimes even cats.
This type of indiscriminate humping isn't about mating. Even a dog who is frenzied by hormones knows the difference between a receptive partner and someone's leg. It's not even about pleasure, although that may play a role. Dogs mainly hump because they're trying to assert themselves. The longer they get away with it, the more powerful they feel.
Humping usually starts during a dog's adolescence - between 6 months old and 2 years old - depending on the breed. This is the time when reproductive hormones are starting to reach adult levels, and some dogs go a little bit crazy. And dogs are always trying to prove that they're tougher than the next guy. Some do it by humping. Others do it by putting their feet on another dog's back. They reach sexual maturity before they reach emotional maturity
Humping is not strictly a male behavior, although males are the worst offenders. Unlike females, whose hormones ebb and flow with their reproductive cycles, males maintain fairly steady hormone levels all the time. The hormones themselves don't cause humping, but they make dogs more likely to do it. That's why neutering or spaying is the best way to reduce or eliminate this unpleasant behavior.
There's another reason that males are more likely than females to latch on to human legs, one that has nothing to do with reproductive urges. Males are just more competitive. They're always trying to prove (to people as well as to other dogs) how big and tough and independent they are. Humping is just one way in which they push the boundaries and assert their dominance within a family.
Watch a litter of puppies at play, and you'll see that they spend quite a bit of time climbing on top of each other. The more assertive dogs may take advantage of their position and throw in a little humping. It's their way of saying that they are, quite literally, top dogs. They hump to show their dominance more than for any other reason.
Once dogs are out of the litter and living with people, the same instinct remains. Human legs don't have special appeal, but they're accessible and easy to wrap paws around. In the wild, dogs never mount dogs who are higher in rank than they are. The only time that a dog tries this with people is when there's some confusion in his mind about who's in charge and who isn't.