The court issued its ruling in a legal challenge to a Riverside ban in 2010. It's estimated another 200 jurisdictions have prohibitions on retail marijuana sales.
California is one of 18 states allowing medical use of marijuana. It is the only state that doesn't have a system for regulating growers and sellers.
California is also the only state that allows residents to obtain a doctor's recommendation for any ailment the physician sees fit. Others allow access only for conditions like AIDS and glaucoma.
"While some counties and cities might consider themselves well-suited to accommodating medical marijuana dispensaries, conditions in other communities might lead to the reasonable decision that such facilities within their borders, even if carefully sited, well managed, and closely monitored, would present unacceptable local risks and burdens," Justice Marvin Baxter wrote for the seven-member court.
Marijuana advocates blamed the absence of state oversight and the failure of local authorities to adopt operating guidelines that fall short of banning dispensaries for the court's decision.
Two bills are pending in the California Legislature that seek to establish a new statewide system for regulating and licensing the medical marijuana industry, and to clarify the role of dispensaries in it. Advocates hope to see language that would make it harder for local governments to outlaw dispensaries by requiring voter approval for any bans, Drug Policy Alliance Policy Manager Amanda Reiman said.
Activists also are in the early stages of planning a ballot initiative that would legalize the recreational use of marijuana and regulate it like alcohol, as voters in Washington and Colorado did last year.
Although the number of dispensaries in California is estimated to have totaled well over 1,000 a few years ago, the local bans and a coordinated crackdown that the state's four federal prosecutors launched in October 2011 have cut their numbers significantly.
Marijuana remains illegal under federal law, and the U.S. attorneys have threatened to seize the property of landlords who lease space to the shops. Hundreds of dispensary operators have since been evicted or closed voluntarily.
The Associated Press contributed to this report.