
As it's only happening when you take him out it could to be due to excitement of the walk, or, I wonder if perhaps he feels a little insecure while out and the humping makes him feel better, like a coping mechanism?
If it's a nervous thing then giving him something to do that he enjoys should help (fetch/tuggy toy/obedience work if he enjoys that). If it's an excitement thing then re-directing that excitement onto something else will help (fetch, tuggy toy etc.), so either way - disraction :)