They use the bargaining to set contract terms that restrict how people can be fired.
A union member who gets in trouble can leverage union resources and representation to protect themselves.
One of my family members did a term as a union rep. He was getting really frustrated with some of the little claims that union members wanted to use the union to protect themselves from, but it was part of the job. Fortunately for him there wasn’t a serious incident like this to deal with during his term.