Q: If we commit a sin in this world and we are punished for it (e.g.. by going to prison or being lashed), then does this punishment reduce or eliminate the punishment in the hereafter?
A: Any punishment meted out in this world for a crime, does not exonerate the perpetrator in the hereafter unless he or she has repented before death. The purpose of worldly punishments is to maintain law and order, and to preserve the rights and dignity of fellow human beings. If there was no punishment for crimes in this world, there would be total chaos and carnage. So these punishments are not ordained to bring automatic forgiveness to the one who commits them.
However, it is possible that while receiving that punishment or immediately thereafter the individual might be driven towards repentance. This will Insha Allah, secure forgiveness in the hereafter. In short, forgiveness in the hereafter only comes through taubah or repentance. The physical punishment received for a crime in this world has nothing to do with repentance in the akhirah. That's why it is possible for a person to evade punishment in this world, and then make sincere taubah and be saved in the hereafter, too. By the same token, it is possible that a criminal is punished here, and due to lack of taubah is also chastised in the hereafter. Salvation in the hereafter (akhirah) is therefore pinned to taubah or repentance.