A bakery owner's lawyers argued that making the cakes violates her Christian beliefs and free religious expression.
The judge ruled the act of making cakes is protected as artistic expression and does not violate a state anti-discrimination law.
A similar case in Colorado is awaiting a US Supreme Court decision.
"A wedding cake is not just a cake in a Free Speech analysis. It is an artistic expression by the person making it that is to be used traditionally as a centerpiece in the celebration of a marriage," Kern County Superior Court Judge David Lampe wrote.
Tastries Bakery owner Cathy Miller said she was "very happy to serve everything from my cases to anybody", but she could not "be a part of a celebration that goes against my lord and saviour".
The US Supreme Court is set to rule on a similar case involving Colorado baker Jack C Phillips, who argues that he can refuse service to same-sex couples based on the First Amendment right to free speech and free exercise of religion clause.
The court heard arguments in the Masterpiece Cakeshop v Colorado Civil Rights Commission case in December.
The California case began when Ms Miller refused service to Mireya and Eileen Rodriguez-Del Rio, who requested a cake without any words or messages.
According to court documents, Ms Miller said she would refer their order to competitor bakery Gimme Some Sugar "because she does not condone same-sex marriage".
The couple filed a complaint with California's Department of Fair Employment and Housing, which ruled in their favour, citing the state's Unruh Civil Rights Act that bars discrimination based on race, gender, religion or sexual orientation.
The state argued that the First Amendment did not apply since the couple had asked for a cake without a message.
Judge Lampe rejected the agency's decision, contending that the wedding was an example of the couple engaging in speech, which "could not be a greater form of expressive conduct".
But he warned that the ruling should not be taken as applicable to other circumstances.
"A retail tire shop may not refuse to sell a tire because the owner does not want to sell tires to same sex couples," Judge Lampe wrote.
"No baker may place their wares in a public display case, open their shop, and then refuse to sell because of race, religion, gender, or gender identification."