ObjectiveThis study aimed to assess the costs and factors associated with the judicialization of medicines for the municipal Unified Health System in Campinas, São Paulo, Brazil, from 2017 to 2021. MethodsThis cross-sectional study used data provided by the Municipal Health Department of Campinas and the Court of Justice of the State of São Paulo. ResultsThe sample comprised 506 medicines (322 active substances) and 493 legal cases. Of the US$9.270 million disbursed, 67.3% were allocated to purchase medicines. On average, 28.8% of the pharmaceuticals were listed on the National List of Essential Medicines (Rename), of which 52.3% were listed in the specialized component. Expenditures on nonincorporated and oncological medicines accounted for 76% of the total value. Acquisition of brand-specific medicines was predominant (53.7%), of which 75.5% had therapeutic equivalents. ABC curve shows that only 28 active substances corresponded to 79.8% of the expenses incurred to serve 573 plaintiffs. Four factors, when present in legal actions, prevented the rational use of public resources: assumption of responsibilities of other federative entities, acquisition of medicines not incorporated in Rename and oncological drugs, trademark determination, and the requirement to supply the medicine for an indefinite period. Costs associated with these factors caused an increase in expenditure, even with a decrease in legal demands filed against the municipality. ConclusionsJudicialization of medicines in Campinas from 2017 to 2021 required an allocation of US$6.2 million, aimed at treating only 0.068% of the population. Associated factors include legal requirements and internal management challenges that have increased costs.