They don’t have to. But there’s an easy way for unions to go around this: figure out how much of the dues go for real union activities, and how much goes to pay lobbyists and engage in other “political” activities, and members of the bargaining unit can decide whether to pay just the basic dues vs. the “enhanced” dues that they can voluntarily pay to support the lobbying effort, etc., as well as the basic union functions. ...But you better make sure your accounting is solid, which is very difficult to do.
Keep in mind, we’re talking about private sector unions, like the Teamsters or the Steelworkers. Public sector unions, like teachers or other government employees, are different. SCOTUS has ruled that it is impossible in public sector unions to separate their workings into strictly union business stuff vs. issues affecting the public interest (since they’re public, after all). Consequently, mandatory dues paying in any amount constitutes speech or expression, since it is a financial endorsement of the union’s stance on issues of public interest. So, bargaining unit members can choose not to financially support the union.