As You Like it opens during a state of conflict between two brothers. The true duke, or Duke Senior, as he is called in the play, has been exiled from his kingdom by his younger brother, Frederick. He has not left by choice; he has been forced out now that his brother has seized power. This is what puts many of the characters in the forest at the start of the play, since many of the older Duke's followers actually follow their leader into exile.
The only reason that Rosalind is allowed to stay at court at the start of the play is because she is very close with her cousin, Celia, who is also the younger Duke's daughter. Eventually, she is is also exiled to the forest.