What is it called when you "justify" things to yourself like this?
Solution 1:
To expand on Yosef's suggestion: the phrase "sour grapes" is often used as a shorthand allusion to Aesop's fable of "The fox and the grapes," in which a fox tries to reach some grapes, is unable to, and tells himself that they were sour anyway—rationalizing the unattainable as undesirable.
Solution 2:
This is called Rationalization.
https://en.m.wikipedia.org/wiki/Rationalization_(psychology)