I agree with @Leanne1986. When my dog was a puppy we would laugh when we saw him humping his stuff animal. He seemed to do it as we all sat in the living room watching tv. He would hump the animal across the room while looking at us and then go back across the opposite way. The more attention we paid him the more he did it. As we grew less interested, so did he.
I think he did it when he wanted attention or felt stressed. When we would have company who would ignore him, he would do it again until they cheered him on. Then he would keep going until either he got tired or they got bored. If the company paid him regular attention,like giving him hugs or petting him, then he was less likely to do it unless they got him really excited by getting him to chase a toy. Not in a sexual way but I think when he got overly stimulated, he needed to do something that would calm him down. It was a quick workout that would end in him taking a nap. He wasn’t always erect, he just did the motion till he was tired. Guess it is a dogs way of lifting weights. LOL
He never humped people though. If they hump people then I would guess it is dominance behavior.