It depends on the union contract.Unionization doesn't automagically mean lazy employees abound.
What you describe is my observation as well. Unions can cause problems, but they can also solve problems. Unions can solve very broad problems that individuals cannot.
Some unions are more powerful and effective than others. Some are very good at helping union members, others not so much.
I see two big difficulties in a programmer union.
1. Skills are different and hard to quantify. One person is highly skilled in one tool, another is highly skilled in another tool. Both are very productive, but they are not directly interchangeable. Alice is an expert in MySQL, Bob is an expert in PostgreSQL, Charlie is an expert in Oracle. While any of them can likely write up a solution for generic SQL problems, for other problems one of them is going to be the best choice for your specific workplace. Similarly, Dan knows DirectX and Emma knows OpenGL, both are great graphics programmers, but they are not directly interchangeable.
2. Too many programmers have giant egos, thinking they are a special snowflake that is irreplaceable. Often they imagine there might be a bell curve or other distribution, but whatever the distribution is, they are skewed at the highest top 1% of them all. A little dose of reality, it is a bell curve and the vast majority of people are average. This is largely fed by the first problem, where they look around the workplace and notice that they are a domain expert. The thought "I am the domain expert on my team", wrongly translates to "I am the domain expert globally". Whatever your specific domain, you are easily replaced by others who are expert in that domain.
It is easy to get caught up in that. I am the only person with my exact skill set, so feel I'm highly valuable and difficult to replace. While it is true that my EXACT skill set is difficult to replace, others with SIMILAR skill sets can more or less overlap my job duties and replace me, with others in the team filling in the gaps.
Other tasks done by unions, such as group negotiation of salaries, become a little more difficult because of the individual variability. As a programmer I can potentially leverage my own specialty for higher pay, but in practice that rarely happens, in most workplaces the programmer is just a cog in the machine paid in the same bucket range as others.