The passenger was forced to pay an additional €20 fee to carry her 10kg luggage on board.
Ryanair allows only small bags as hand luggage if they can be stowed beneath the seat in front.
More: Air traffic control blamed for 11,000 Ryanair flight delays
Comment: Ryanair to cut aircraft, pilots and crew, but who is to blame for surplus?
The budget airline said it would not change its baggage policy.
Having paid €35.69 for the flight in January, the passenger attempted to board with a handbag and a small suitcase, which fitted in the overhead baggage space and did not weigh more than 10kg.
But she was told she had to pay extra as she had not bought a Priority ticket.
The airline has a policy of charging customers an additional fee for carrying anything more than one personal item on board. Larger bags can also require a luggage fee.
The Spanish commercial court ruled that the woman should be refunded with interest, it was reported.
The Madrid judge ruled that the hand luggage, by size and weight, could be easily carried in the cabin, pointing to a Spanish regulation that allows passengers to take hand luggage on board at no additional cost.
The judge characterised the charge as abusive, adding that it “curtailed the rights that the passenger has recognised by law”, and declared it invalid in Spain.
But she rejected the demand for compensation, saying that while doubtless “the passenger suffered rage and powerlessness in having to pay the extra unforeseen cost at the time of boarding” the discomfort did not reach a level that would justify compensation.
The airline said: “This ruling will not affect Ryanair’s baggage policy, either in the past or in the future, as it is an isolated case that misinterpreted our commercial freedom to determine the size of our cabin baggage.”
The ruling cannot be appealed.