In many industries it's a requirement of the bargaining agreement. But many states have passed 'right to work' laws which state you can't be forced.
And still, I know of positions where there are 'union' and 'non-union' people basically doing the same job at companies. Non-union usually comes with a pay bump to offset not having the union benefits.