"Last group, another lap."
"I need another 20 minutes to make up for that carrot cake."
Any of that sound familiar? It's training as punishment.
Training as Punishment. This is the more common of the two ideas. It's basically that exercise is a way to atone for, make up for, or earn forgiveness for errors or insufficient effort. It's also a way to retroactively earn an already-taken reward.
The irony here is that a standard gym teacher/coach/disciplinarian approach is to punish those who have the most trouble exercising effectively with addition reps of whatever they do poorly. Can't do pushups well? Then do more of them to make up for it. Didn't run fast? Run more. That'll teach you speed, for sure, all that extra exhausted running. It makes sense when the punishment is aimed at something other than fitness - gut checks in a boot camp situation to see who will quit and who will persevere, to encourage competition where finishing last will result in real world consequences, and so on. But it doesn't make much sense to punish the out of shape with more reps of something they can't do.
Training as Reward. This is better stated as "time off from training as a reward." This is, I didn't eat cake so I don't need to exercise. This is anathema to exercise junkies, but it's also rightly anathema to a training plan. If you are training with a purpose, with an end goal in mind, you can't break up that consistency as a reward for following other parts of that program. Again, no amount of outside action is going to make up for missed gym days, either. Extra sleep, eating extra-well (however you define that), or what have you won't replace a missed squat session or that cardio work you needed to get in. Swapping out one kind of training for another is fine, but that's not punishment/reward, that's making modifications to a training program.
This is a great quote in this article over on Starting Strength that embodies the ideal in training:
"I learned to train with purpose rather than for atonement." (italics in the original) - Gillian Mounsey
It's that "atonement" that gets you in trouble.
It's worth saying this outright: nothing you do in the gym will make up for things you did outside the gym. No training is going to be enough to overcome a poor diet.
Sure, a single cheat meal or an extra dessert during the week will get ground down by a set of squats. But a blip on a healthy eating lifestyle is just a blip regardless of your training. You don't need to punish yourself for it. An conversely you can't punish yourself enough to make up for a bad diet, poor food choice, inconsistency in training, or anything else. All it does is make training punishment.