We rationalize after acting against our own beliefs.
Holding two contradictory ideas at the same time (or acting against what we believe) creates real discomfort. To resolve it, we don't usually change the behavior we already carried out. We change the belief, so the two fit together again.
In a now-classic experiment, participants were paid to perform a very boring task and then tell the next person that it had been enjoyable. One group was paid $1 to lie, and another, $20. Counterintuitively, those who received only $1 ended up rating the task as genuinely more enjoyable than those who received $20. With $20, they had a clear external reason for lying. With $1, that wasn't enough justification, so they resolved the contradiction by changing their own opinion of the task.
When an action and a belief conflict, and we can't undo the action, we adjust the belief to reduce the discomfort of the contradiction. It's easier to change our mind than to admit we acted without a good reason.
Source: Festinger, L. & Carlsmith, J. M. (1959). Cognitive Consequences of Forced Compliance. Journal of Abnormal and Social Psychology, 58(2), 203-210.
When someone invests effort, time, or money in a decision (a purchase, a membership, a course), they tend to justify it afterward, even in the face of signs that it wasn't ideal. Understanding this helps design the "after" of a decision better, not just the moment of deciding.
Related concepts