I don't get how the death penalty discourage murderers. It's a little confusing to me.

In my opinion, the death penalty doesn't deter murderers.

The idea is that a person who wants to commit murder won't do it if s/he knows the penalty is death.

However, reality includes the following:

Murderers (and other criminals) don't believe they will be caught.
Murderers are so angry and distraught they don't care if they die.
Many criminals are immature and do not (or cannot) consider the consequences.

Anecdotal evidence:

A long time ago, pickpockets were publicly hung in England. Yet -- pickpockets often practiced their trade among the crowds at these hangings!