Because of the ways Hamlet sees both his mother and Ophelia bending to the will of the men in their lives—and therefore aligning themselves against him—he views women as the weaker sex, whose loyalties are fickle.
When the main action of the play begins, Hamlet has already watched his mother quickly move from being his father's widow to being the new bride of his uncle. Eventually, he confronts her; some directors interpret the lines in act 3, scene 4 as particularly violent:
Have you forgot me?
No, by the rood, not so.
You are the queen, your husband’s brother’s wife,
And—would it were not so!—you are my mother.
Nay, then I’ll set those to you that can speak.
Come, come, and sit you down. You shall not budge.
You go not till I set you up a glass
Where you may see the inmost part of you.
What wilt thou do? Thou wilt not murder me?
Help, help, ho!
Because he feels that his mother has betrayed both himself and his father's memory, Hamlet declares that he wishes Gertrude wasn't his mother at all. He seems sincere in these lines, provoked to such anger that he rushes at the voice behind the curtain and kills Polonius.
In the recent past, Hamlet has also been close to Ophelia, and evidence points to the fact that he really did love her. Yet this daughter of Polonius is swallowed up by the plans Polonius and Claudius concoct, and they use her to try to determine Hamlet's motives and mental state. Hamlet realizes that she is no longer faithful to him, and he verbally attacks her in act 3, scene 1:
Ay, truly, for the power of beauty will sooner
transform honesty from what it is to a bawd than the
force of honesty can translate beauty into his likeness.
This was sometime a paradox, but now the time gives it
proof. I did love you once.
Indeed, my lord, you made me believe so.
You should not have believed me, for virtue cannot so
inoculate our old stock but we shall relish of it. I
loved you not.
I was the more deceived.
Get thee to a nunnery. Why wouldst thou be a breeder of
Hamlet toys with Ophelia's emotions here, telling her both that he once loved her and that he never did. He tells her that she's only capable of breeding sinners, which reflects his view of women in general, which is based on the actions of the two women he's trusted most and who have proven disloyal to him. He goes on to tell Ophelia that "wise men" are fully aware that women make "monsters" out of them. Hamlet's manipulations (combined with those of Polonius) drive Ophelia to commit suicide.
Hamlet has no women in his trusted inner circle, and the two women he's trusted most have let him down. Therefore, Hamlet's perception of women is that they are untrustworthy and disloyal, and this furthers his own feelings of alienation.