According the supremacy clause of the Constitution, Federal law supersedes state law. However, when the people of a state, by referendum or through elected officials, make a decision, the Federal government takes note. One of the theories of having many states is that states can try out different policies and the rest of the country can observe the results. The Federal government has decided not to interfere in states that have legalized marijuana. It could chose to do so at any time.
In the US, why don't States have to follow Federal law? ie marijuana is illegal according to Federal law, but some states have made it legal for recreational use.
Technically ... Federal law only applies to federal property. They also use their authority over interstate commerce to impose federal law on any entity that uses interstate communications - such as telephones, mail, or internet.
There was actually a movement a couple years ago in Montana, to have a gun manufacturer that only sold firearms in state - so federal regulations wouldn't apply.