In a 16-page order, state District Judge David Thomson dismissed a lawsuit that alleged Castillo had failed to gather enough petition signatures to make the ballot this year. The suit argued that some of the signatures Castillo submitted were invalid because they were duplicates or had other problems.
Thomson held an all-day hearing on Friday to consider evidence in the case.
The ruling sets up a two-person race for state treasurer between Castillo and incumbent Tim Eichenberg, a Democrat.
Castillo is a retired chief financial officer who used to work in the state Treasurer’s Office.
Castillo acknowledged on the stand Friday that he had, at one point, considered dropping out of the race. But he decided to stay in the race after talking to friends and family.
If he does drop out eventually, the Republican Party can replace him on the ballot with a different candidate.