Voluntary unions do not have a free rider problem. That is only the case if you legally require collective bargaining to apply to non-union members (as is the case in the US).
For instance, in Germany [1] collective bargaining agreements are agreements between employers and unions, and are only required to be applied to union members. Companys may voluntarily choose to extend those same benefits to non-union members. Despite the fact that unions are voluntary in Germany, they still have significant union membership as a whole and German unions are frequently held up as a good example of the benefits of unions to both workers and society which is evidence against the claim that it is necessary to legally enforce union membership.
[1] https://www.diw.de/documents/publikationen/73/diw_01.c.86564...