We have a system in the United States in which there is state law and federal law. For the most part, federal law covers the areas that are enumerated in Article I of the United States Constitution. Areas not enumerated in Article I are areas of law that are covered by individual states. This is why most family law, divorce and custody, for example, varies from one state to the next. Most crimes, too, are a matter of state law, with a few exceptions listed in Article I. Each state has its own criminal code, and these can vary, too.
There are some area of overlap, as well. One example of this is the fact that there is a federal minimum wage law, which Congress can create because this minimum wage law applies to interstate commerce, part of its enumerated rights to legislate. At the same, there are states that have their own minimum wage laws, and these apply to any commerce that is within the state borders. These run side by side, with no conflict.
However, there are situations in which state and federal law do conflict. Environmental regulation is one such area, with some states having higher or lesser standards for air pollution control, for instance. Another area of conflict is immigration, since in recent years, some states have begun to create legislation to control immigrants within their states.
This brings us to a doctrine called "preemption." Preemption is the doctrine that says that when federal legislation and the legislation of any particular state are in conflict, the federal legislation usually trumps the state legislation. Whether or not preemption applies is usually left up to the courts to determine. But as a general rule, most federal legislation preempts or trumps state legislation.
All of that leads us to your question. How in the world can an activity be legal and illegal simultaneously? The fact is that while it is true that marijuana use can be perfectly legal in a state, it remains illegal under federal law. I am not aware of anyone making a serious argument against the preemption doctrine as it applies to this situation. There is no doubt that federal law preempts state law in this case.
The answer really lies in a more practical realm. The state will not prosecute marijuana use within its boarders. However, the federal government is free to prosecute marijuana use in any state in the United States. The fact that it is legal in a particular state is not a defense at all in such a prosecution. The person using marijuana anywhere in the country is committing a federal crime.
At the present time, the federal government has decided to not prosecute most kinds of marijuana cases. This is what is known as prosecutorial discretion. A prosecutor gets to decide which cases he or she will prosecute or not prosecute. The nation's chief prosecutor, the United States Attorney General, is part of the executive branch of government. Our executive branch, i.e. President Obama, has decided that the federal government is not generally going to exercise its power and right to go against individual marijuana users and to not invoke the preemption doctrine to do away with the state laws that legalize marijuana, medically, recreationally, or both.
However, at any given time, the federal government is within its rights to change its policies and enforce the federal laws against marijuana. A change in policy in this administration could do this, or a change in administration, in other words, a new president, could result in prosecution and/or invocation of the preemption doctrine.