How do indulgences remit temporal punishment?
Sin has consequences!
"Sin has two consequences, or punishments (CCC 1472). The first is eternal punishment, in which the soul loses heaven and is confined to an eternity in hell. This punishment is remitted through the forgiveness of sins. The second is temporal punishment, in which a person must expiate, or make reparation for his sins. This temporal punishment remains even after sin is forgiven."
"How does one expiate his sins? The Catholic Church has traditionally identified three major ways–prayer, fasting, and almsgiving. Any good work or sacrifice expiates sin, as well as patiently bearing our sufferings and offering them up in satisfaction for our sins (CCC 1459-1460)."
"What happens if one has not fully expiated his sins before dying? Such a person, before going to heaven, would have to expiate his sins in purgatory (CCC 1030), where love for God is perfected through our sufferings there. Traditionally, the sufferings of purgatory have been compared to a "consuming fire" (1 Cor. 3:11-15). Because certain sins can be forgiven "in the age to come" (Matt. 12:32), Catholics have always prayed for the dead–for the relief of their souls, or their speedy deliverance, if they are in purgatory, for "it is a holy and wholesome thought to pray for the dead, that they may be loosed from their sins" (2 Macc. 12:46)." - Temporal Punishment and Sin.
Indulgences are a remission of temporal punishments due to sin which have been sacramentally confessed and then absolved, thus making our purification in purgatory shorter. Indulgences do not affect consequences of sin, like gaining HIV from fornication!
Here are some general guidelines for gaining indulgences from the Apostolic Penitentiary of the Vatican.
General Remarks On Indulgences
This is how an indulgence is defined in the Code of Canon Law (can. 992) and in the Catechism of the Catholic Church (n. 1471): "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".
In general, the gaining of indulgences requires certain prescribed conditions (below, nn. 3, 4), and the performance of certain prescribed works (nn. 8, 9, 10 indicate those specific to the Holy Year).
To gain indulgences, whether plenary or partial, it is necessary that the faithful be in the state of grace at least at the time the indulgenced work is completed.
A plenary indulgence can be gained only once a day. In order to obtain it, the faithful must, in addition to being in the state of grace:
have the interior disposition of complete detachment from sin, even venial sin;
have sacramentally confessed their sins;
receive the Holy Eucharist (it is certainly better to receive it while participating in Holy Mass, but for the indulgence only Holy Communion is required);
pray for the intentions of the Supreme Pontiff.
It is appropriate, but not necessary, that the sacramental Confession and especially Holy Communion and the prayer for the Pope's intentions take place on the same day that the indulgenced work is performed; but it is sufficient that these sacred rites and prayers be carried out within several days (about 20) before or after the indulgenced act. Prayer for the Pope's intentions is left to the choice of the faithful, but an "Our Father" and a "Hail Mary" are suggested. One sacramental Confession suffices for several plenary indulgences, but a separate Holy Communion and a separate prayer for the Holy Father's intentions are required for each plenary indulgence.
For the sake of those legitimately impeded, confessors can commute both the work prescribed and the conditions required (except, obviously, detachment from even venial sin).
Indulgences can always be applied either to oneself or to the souls of the deceased, but they cannot be applied to other persons living on earth.