Madness is an ongoing theme throughout Hamlet. It emerges primarily in two characters, Hamlet and Ophelia, but other characters comment on it, speculate about it, etc. This makes it seem like madness is a common possibility, and something that happens to people, like a storm.
In Hamlet's case, the main suggestions for why he might be mad are love for Ophelia and the loss of his father/remarriage of his mother. However, he is but pretending to be mad, so he can investigate Claudius.
In Ophelia's case, she actually loses it. She ends up dying as a result, unbalanced by the loss of Hamlet's love, his actions towards her, and, of course, his killing of her father.