Catholics believe in indulgences because ultimately we know we're all sinners and need God's mercy. When a person commits a sin, there are two kinds of punishments that they have to deal with as a result of that sin. The first is called 'eternal punishment' which means the sinner can't enter heaven because of a grave sin that is not repented from. Through Christ's sacrifice we don't have to suffer eternal punishment if we repent. The second kind of punishment is called 'temporal punishment' and every sin we commit carries a temporal punishment with it.
Temporal punishment is not God getting back at us for disobeying Him. We bring it on ourselves. It's like if you shatter your friend's iPhone screen and they don't have insurance. They'll probably forgive you (in God's case He always forgives us in the Sacrament of Reconciliation) but you still have to pay for your friend to replace their phone.
Purgatory is one of the ways we make reparation for our sins and pay back our temporal punishment so that we can get to heaven. The exciting part is that we can get a head start on fulfilling our temporal punishment through indulgences.
'An indulgence is a remission before God of the temporal punishment due to sins whose guilt has already been forgiven, which the faithful Christian who is duly disposed gains under certain prescribed conditions through the action of the Church which, as the minister of redemption, dispenses and applies with authority the treasury of the satisfactions of Christ and the saints.' (CCC 1471)
There are both 'plenary' and 'partial' indulgences. Plenary means you're released from all of the temporal punishment you need to fulfill, and partial means you're released from some, or a part of it. There are certain feasts during the year on which you can obtain an indulgence by doing the acts of devotion, penance, and charity required. The Church is trying to inspire us to do good works, while using its treasury of the graces from Christ and saints to help us get to heaven. (CCC 1478)
You can gain an indulgence for yourself, or for someone who's already passed away and may still be in Purgatory.