The beginning of the movie shows icemen harvesting ice. A young boy named Kristoff and his pet reindeer, Sven, is among them ("Frozen Heart"). Elsa, Princess of Arendelle, possesses cryokinetic powers, with which she is able to produce or manipulate ice, frost and snow at will. One night while playing, she accidentally injures her younger sister, Anna. Their shocked parents, the king and queen, seek help from the troll king, who heals Anna and removes her memories of Elsa's magic. The royal couple isolate the sisters in the castle until Elsa learns to control her magical powers. Afraid of hurting Anna again, and with her ability to control her powers deteriorating, Elsa spends most of her time alone in her room, refusing even to speak to Anna and a rift develops between the sisters as they grow up; when the girls are teenagers, their parents die at sea during a storm ("Do You Want to Build a Snowman?").
When Elsa comes of age, the kingdom prepares for her coronation ("For the First Time in Forever"). Among the guests is the Duke of Weselton, who seeks to exploit Arendelle for profit. Excited to be allowed out of the castle again, Princess Anna explores the town and meets Prince Hans of the Southern Isles; the two quickly develop a mutual attraction. Despite Elsa's fears, her coronation takes place without incident. During the reception, Hans proposes to Anna, who hastily accepts ("Love Is An Open Door"). However, Elsa refuses to grant her blessing and forbids their sudden marriage. The sisters argue, culminating in the exposure of Elsa's abilities in an emotional outburst.
Declared a monster by the Duke, a panicking Elsa flees the castle, while inadvertently unleashing an eternal winter on the kingdom. High in the nearby mountains, she abandons her restraint, vowing to never return and building herself a solitary ice palace ("Let It Go"). Meanwhile, Anna leaves Hans in charge of Arendelle and sets out in search of her sister, determined to return her to Arendelle, end the winter and mend their relationship. While obtaining supplies from 'Wandering Oaken's Trading Post and Sauna', Anna meets Kristoff and Sven ("Reindeers Are Better Than People"). She convinces Kristoff to guide her up the North Mountain. On their journey, the group encounters Olaf, Anna and Elsa's childhood snowman whom the latter recreated and unknowingly brought to life. Olaf dreams of seeing and experiencing summer for the first time ("In Summer"). He then leads them to Elsa's hideaway.
Anna and Elsa reunite, but Elsa still fears hurting her sister. When Anna insists that Elsa return, she becomes agitated and her powers lash out, accidentally striking Anna in the heart ("For the First Time In Forever (Reprise)"). Horrified, Elsa forces Anna, Kristoff and Olaf to leave by creating a giant snow creature named Marshmallow that chases them away from her palace. As they flee, Kristoff becomes concerned when he sees Anna's hair turning white. He seeks help from the trolls, his adoptive family, who explain that Anna's heart has been frozen by Elsa ("Fixer Upper"), and that unless it can be thawed by an "act of true love", she will become frozen solid forever. Believing that only Hans can save her with a true love's kiss, Kristoff races back with her to Arendelle.
Hans, who is himself leading a search for Anna, reaches Elsa's palace. In the ensuing battle against the duke's men, Elsa is knocked unconscious by a falling chandelier and imprisoned in Arendelle. There, Hans pleads with her to undo the winter, but Elsa confesses that she has no idea how. When Anna reunites with Hans and begs him to kiss her to break the curse, Hans refuses and reveals that his true intention in marrying her is to seize control of Arendelle's throne. Leaving Anna to die, he charges Elsa with treason for her younger sister's apparent death.
Elsa escapes and heads out into the blizzard on the fjord. Olaf comes across Anna and reveals Kristoff is in love with her; they then escape onto the fjord to find him. Hans confronts Elsa, telling her Anna is dead because of her. In Elsa's despair, the storm suddenly ceases, giving Kristoff and Anna the chance to locate each other. Nevertheless, Anna, seeing that Hans is about to kill Elsa, throws herself between the two just as she freezes solid, blocking Hans' attack.
As Elsa grieves for her sister, Anna begins to thaw, since her decision to sacrifice herself to save her sister constitutes an "act of true love". Realizing love is the key to controlling her powers, Elsa thaws the kingdom and gives Olaf his own personal flurry so he can survive in summer. Hans is deported to the Southern Isles to face punishment for his crimes against the royal family of Arendelle, while Elsa cuts off trade with Weselton. The two sisters reconcile and Elsa promises never to shut the castle gates again.

Question: Why does Elsa flee the castle?
Answer: Her powers were exposed. 
Alternative answer: The Duke declared her a monster.