I expect it is barrier frustration when out on walks and of course he thinks that barking is making the dogs go away, he has no idea that they will pass anyway.
Dogs learn by cause and effect, he barks = dogs go away therefore his barking is making the dogs disappear.
I would try to prevent him practising this behaviour as of course the longer he does it the better he will get at it.
Look here for a potential solution.
http://www.clickersolutions.com/articles/2001c/manicbarking.htm