It has and it can.
What a law does is establish a potential penalty to be applied to those who were caught and convicted of breaking it.
A law really doesn’t do much else, and a law certainly does not prevent whatever behavior it is untended to punish.