It is law. Non-union shops may not bid on publicly funded projects. There are no ifs, ands, or butts. Three miles of highway need to be repaved? Your Asphalt company has 1000 employees, and has an exemplary record of service? It is not union? You are legally prohibited from bidding on the project.
As to your second question, no, of course their is no law stating who for or where you may work. That's not germane to our exchange however. Your position seemed to imply that there was no such thing as forced union membership. I simply provided an example of where there is.
NY laws are unjust? I shouldn't doubt that.
The law to which you refer, sounds, on the surface, to be unjust. Considering the level of political clout I've been led to believe unions have in NY, I don't doubt that it may be.
Those workers though, are not forced to be union. There is a whole non-union economy out there, albeit in different industries.