By Dan Levine

SAN FRANCISCO (Reuters) - The U.S. Department of Justice cannot spend money to prosecute federal marijuana cases if the defendants comply with state guidelines that permit the drug's sale for medical purposes, a federal appeals court ruled on Tuesday.

The ruling, from the 9th U.S. Circuit Court of Appeals, comes as voters in nine more states will consider allowing the recreational use of marijuana this November.

Twenty-five U.S. states currently allow for medical marijuana. While the sale of the drug is still illegal under federal law, Congress in 2014 passed a budget rule which prohibits the DOJ from using federal funds to interfere in the implementation of state marijuana regulations.

Due to this rule, defendants in 10 cases in California and Washington argued that their federal charges should be dismissed. The 9th Circuit in San Francisco, which covers nine Western states, ruled on Tuesday that the DOJ could not spend money as long as those defendants "strictly complied" with all state regulations.

The appeals court sent the cases back to lower courts to determine if the defendants had complied with state law.

A Justice Department spokesman could not immediately be reached for comment.

In November California and eight other states will consider whether to allow marijuana for recreational use. Colorado, Washington, Oregon and Alaska, as well as the District of Columbia, already permit it.

The unanimous 9th Circuit ruling on Tuesday was issued by a three-judge panel, two of whom are Republican appointees with a history of pro-law enforcement opinions.

Despite the outcome, however, Judge Diarmuid O'Scannlain wrote that medical marijuana purveyors should not feel immune from federal law.

"Congress could restore funding tomorrow, a year from now, or four years from now," he wrote, "and the government could then prosecute individuals who committed offenses while the government lacked funding."

(Reporting by Dan Levine; Editing by Alan Crosby)