The elderly woman, who has “a very limited capacity to make decisions”, had been due to get the jab last week at the care home in the northwestern city of Santiago de Compostela.
Her daughter protested, citing concerns over possible side effects.
The residence then turned to the courts and the judge ruled that the woman “lacked the faculties to provide adequate consent to a medical intervention”, said the ruling.
While the judge sympathised with the daughter's concerns, he said there was “less risk” from the vaccine than from not getting it.
The daughter's position “went against the interests of the resident of the care home regarding the maintenance of her health,” the judge added in his ruling, made public last Wednesday.
He stressed that his decision was based solely on the interests of the elderly woman and not of all the care home's residents. Spain's vaccination campaign is voluntary and no one can be forced to be immunised on the grounds that it would benefit the community.
Like most other European nations, Spain began its immunisation campaign at the end of December, with elderly residents and nursing home staff getting the jab first.
The country has a relatively high level of acceptance of the coronavirus vaccine, with 62 percent saying they are willing to get the jab according to a poll published in December by the Ipsos Global Advisor.