Madness is an ability that lets you play a card when you discard it. While that intuitive explanation sounds simple, the technical machinations the rules use to do this are anything but: First, upon being discarded, the card with madness is exiled instead of being put into the graveyard.
Do madness cards go into graveyard?
When you cast a card with madness, it still counts as being discarded, but it doesn't actually get to your graveyard before you cast it. That means your opponent can't exile it "in response" to stop you from playing the spell.
Is madness a triggered ability?
Madness is a replacement effect and a triggered ability. If you would discard a card with madness, instead of discarding it to the graveyard, instead you discard it to exile and a trigger goes on the stack. When that trigger resolves, you can choose to cast the card for its madness cost.