Schools have always had the ability to curtail the speech of students to maintain orderly learning environments, and governments have always had the ability to set curriculum of schools to decide what students are taught. There's no first amendment right for teacher to teach students about subjects outside their curriculum. The easy example of this is teaching religion. Private citizens have a first amendment right to their own religion, and to their expression of it. Teachers and students alike have a right to their religious expression. However, teachers may not use public classrooms to indoctrinate children into their religions. That would itself violate the first amendment. That's the basis of Engel v Vitale, Abington School District v. Schempp and Tinker v Des Moines among others. Private schools are under no such obligation. What bounds schools are given is a matter of the jurisdiction of government authorities regulating them, and that goes to local, state and federal government. What we have here is a state law superceding local government, which is within their jurisdiction.
When it comes to speech in schools in particular, all these nuanced precedents for first amendment boundaries and rights are necessary because schools lay at an uncomfortable intersection between the rights of an individual to express themselves and a government telling them how to think. If you give all the teachers at a public school the "freedom of speech" to lead christian prayers every morning and teach bible verses, you're violating the first amendment by having the state impose religion on students. If you restrict students from being able to pray on their own private time on school grounds, you're violating the first amendment by suppressing their religion. To navigate those difficulties, the supreme court precedent is to weigh compelling interests and substantial disruptions, to favor individual expression and scrutinize imposition of beliefs.
And falling on the wrong side of imposition of beliefs without any compelling interest, is what you get when teachers are telling kids age kindergarten to 3rd grade about sexual orientation or gender identity, which is not age appropriate or developmentally appropriate by either state standards or any sane standards. Its the right of parents to decide what is appropriate for their children to learn about such matters and when, not for the state to impose its own dogmatic beliefs on children to indoctrinate them into the latest social cult.