I think the word being searched for is displacement behavior. Quote below from wikipedia regarding displacement in humans.
"In psychology, displacement is an unconscious defense mechanism whereby the mind redirects affects from an object felt to be dangerous or unacceptable to an object felt to be safe or acceptable. For instance, some people punch cushions when they are angry at friends; a college student may snap at his or her roommate when upset about an exam grade.
Displacement operates the mind unconsciously and involves emotions, ideas, or wishes being transferred from their original object to a more acceptable substitute. It is most often used to allay anxiety."
My two guys don't do this snarkiness on leash but I could see how it could develop. I have seen displacement before in my cat though. When she has tried to jump to the counter or the top of the sofa and misses, she will stop and clean her front paws. It seems almost like a nonchalant behavior after her failed jump and subsequent slip/fall. Displacement behavior is used because it is soothing to the animal. Although it doesn't seem that attacking your walking partner would be soothing, the dog releases anxiety by attacking their partner who they know is "safe" and can't (or won't be allowed to) hurt them like the unknown dog might be able to do.
A few ideas to try…
Although it seems difficult, maybe more exposure to "new" dogs on leash could help. I.e. if you have a friend or neighbor who has a nonaggressive dog and is willing to help, set up training time where you "encounter" another dog (the friend's dog) and work on either getting the displacing dog to ignore the other dog as it passes on your command or trying a command at the outset like sit. Work at first with treats that your displacing dog will go nuts for (for my boys it is cooked chicken, ham lunchmeat or cheese bits) and consider these as like gold standard treats. Then work down to lesser fabulous treats and then try to phase out treats but keep a "lottery" mentality such that every once in a while they get a fabulous treat for the same behavior. Just like why people gamble, the dogs will continue to do the good trained behavior because they just might "win" a fabulous prize for doing so. You should be able to work down to a lesser treat by the end of the first session. You could also take a squirt bottle with water in it for stopping bad behavior at the outset and reward for just the momentary pause you'll get when your b gets a water spurt on his butt.
Avoiding this situation will only make it worse. oh and make sure to ask for and reward for the same behavior from both dogs.