The headmistress trope in school fantasy is a lot more versatile than people give it credit for. She's rarely just the stern administrator handing out detentions, though that classic figure does exist and serves a purpose – she's the immovable object that the rebellious protagonist has to navigate, establishing the rules of the magical world from day one.
Where it gets interesting, though, is when she's a power in her own right, often the most powerful witch or mage in the region, and the school itself is a piece of her domain. Think Professor McGonagall, but if she'd been the one in charge the whole time. Her role then shifts from simple authority figure to a guardian of both knowledge and the students themselves, a protector against external threats. She becomes a mentor-by-observation, often seeing the potential in the main character long before anyone else does.
Then you have the subversions: the secretly corrupt headmistress running a cult or a dark ritual under the school, which flips the entire dynamic and makes the academy a prison. Or the frail, seemingly oblivious one who is actually a retired legendary hero, a living archive of lost magic. Her true role is as a final test or a hidden benefactor. She can also serve as a direct foil to a young, powerful heroine – that dynamic of a seasoned, politically savvy woman versus a raw, untamed talent creates fantastic tension, especially in stories about duchesses or villainesses reborn at school. The headmistress embodies the system the protagonist must either master, overthrow, or inherit.