Sometimes that is the point of punishment, to get them to change their behavior... but sometimes it isn't...
After all, when you put someone to death, clearly you aren't going to get them to change anything (other than prevent them from doing it again).
And frankly, it doesn't seem to deter much crime either, the general view seems to be that people don't think they'll get caught or don't think it will happen to them. So punishing someone else doesn't seem to do much outside of minor punishments for minor crimes.
Now, that being said, if you want the oil companies to change their behavior, you can do that several ways. One is to change the "rules". After all, if an oil spill happens, that does not mean, by default, that they broke the rules. Accidents happen, it doesn't mean there is always "fault".
One way is to make the punishments harsh for breaking any existing rules... Which is fine, but if you make the punishments too harsh, they either stop being effective or, in the case of large companies, it becomes cheaper to buy off Congress to get their way.