In Act 1, Scene 2, Viola sees herself in what the Captain describes of Olivia:
A virtuous maid, the daughter of a count
That died some twelvemonth since; then leaving her
In the protection of his son, her brother,
Who shortly also died: for whose dear love
They say, she hath abjured the company
And sight of men.
Viola too has lost her father: and she has just lost her brother, so she thinks. The sorrow at these two losses leads Olivia to foreswear men altogether: and Viola completely empathises with her situation:
O that I served that lady
And might not be delivered to the world,
Till I had made mine own occasion mellow,
What my estate is!
How can she serve that lady? By serving Orsino, who constantly sends men to plead his love to her. And that's what she does:
I prithee, and I'll pay thee bounteously,
Conceal me what I am, and be my aid
For such disguise as haply shall become
The form of my intent. I'll serve this duke:
Thou shalt present me as an eunuch to him:
It may be worth thy pains; for I can sing
And speak to him in many sorts of music
That will allow me very worth his service.
Why does Viola dress as a boy? Partly because she is trying to keep her brother alive, who she fears might be dead (she tells us later in the play that she wears his clothes, and in his fashion - and Cesario sounds quite like Sebastian). Partly because Orsino seems to run an all-male court, and it will allow her to be a man-servant (and earn a wage so she can support herself). But she never actually says directly why she decides to cross-dress. It's open to interpretation.
Hope it helps!