Batteries are a commodity. Production can get outsourced to whoever can deliver the best value. Up front costs are smaller and you never have to worry about infrastructure upgrades because there's no special infrastructure. You can just replace your diesel buses with electric as they come due. You automatically get upgrades buses every few years because buses don't last 40+ like trains do and you aren't ever forced to upgrade your overhead electric infrastructure
The wires are planned and owned by an (intentionally) inefficient government bureaucracy and installed and maintained by expensive local labor and you can't just change routes on a whim, you may be forced to do a full system upgrade in the future, etc, etc.
In somewhere like China where the government can just tell people where the trams are going to be and that's that the wires are probably the better solution in more cases. In the west where have to work with the public to get their approval for infrastructure it's generally a better all around solution to buy electric buses to replace your diesel ones even if it is less environmentally efficient on paper.
Edit: Some of you are appear to be taking my factual statement about the efficiency of government poorly. The inefficiency of government is a feature, not a bug. Government that can do good things (like install wires for trams) quickly and fairly unilaterally can also do bad things (like waste money installing wires for trams where nobody wants them) fairly unilaterally. You can't have it both ways and sometimes you just have to work around the system and if that means buying the buses with batteries then that's fine.