In 1943, the US Supreme Court ruled in West Virginia State Board of Education v. Barnette that public schools cannot require students to stand during or to recite the Pledge of Allegiance.
Courts have also ruled that, as long as students are not creating a disturbance, they may sit or raise a fist in protest during the Pledge of Allegiance (Lipp v. Morris, and Holloman v. Harland).
Some states may require parental permission for students to abstain from the pledge. Courts have upheld this requirement (Frazier Frazier v. Winn).
Source: National Youth Rights Association, “The Pledge of Allegiance and the National Anthem,” youthrights.org (accessed July 15, 2021)