WASHINGTON — Tens of thousands of students in California enrolled in online classes at out-of-state colleges abruptly lost federal financial aid this week after they found themselves in the cross-fire of a regulatory fight between Education Secretary Betsy DeVos and the nation’s largest teachers’ union.

The students who lost their aid are the unlikely victims of an effort by the union, the National Education Association, to stop Ms. DeVos from delaying a rule written by the Obama administration to bolster consumer protections for students taking online courses at schools not based in their states.

Ms. DeVos had warned that states were not ready to enforce the rules, and the teachers rebuffed those concerns. A judge sided with the union, leaving the students without aid.

“We tried to delay the implementation of the 2016 rule because of its many flaws — including this consequence for California students,” said Liz Hill, a spokeswoman for the department. “Unfortunately, the N.E.A. filed a lawsuit, and a judge ruled that we have to implement the rule.”