Here is the fuller version of the passage:
At that time some people who were present there told him about the Galileans whose blood Pilate had mingled with the blood of their sacrifices. He said to them in reply: "Do you think that because these Galileans suffered in this way they were greater sinners than all other Galileans? By no means! But I tell you, if you do not repent, you will all perish as they did!
Or those eighteen people who were killed when the tower at Siloam fell on them—do you think they were more guilty than everyone else who lived in Jerusalem? By no means! But I tell you, if you do not repent, you will all perish as they did!
(this and all other Scripture quotes from the New American Bible, Revised Edition)
From the way the first incident is described, it doesn't sound like Pilate was punishing them for some sin; from what little we know about Pilate, it would be surprising if he even recognized the concept of sin. Philo of Alexandria describes him as "a man of inflexible, stubborn and cruel disposition ... [known for] his venality, his violence, his thefts, his assaults, his abusive behavior, his frequent executions of untried prisoners, and his endless savage ferocity." The first thing he did on arrival in Jerusalem was to set up "the effigies of Caesar which are called standards" (Josephus, The Jewish Wars, idem), which reportedly was an intentional violation of Jewish law.
That being the case, how can we understand this saying of Jesus? Consider John 9:1–2:
As he passed by he saw a man blind from birth. His disciples asked him, "Rabbi, who sinned, this man or his parents, that he was born blind?"
Similarly, in John 5:14 Jesus tells a man he has healed,
Look, you are well; do not sin any more, so that nothing worse may happen to you.
These and other quotes illustrate a Jewish belief that sinfulness could cause actual physical punishment (disease, hardship, or even death)—and by extension, that the worse someone was suffering, the worse their sins had been. In this passage from Luke, Jesus appears to be denying this idea; but he does assert that sin without repentance does have consequences.