Is there any idiom or phrase for this?
refusing to admit one's mistake or one's own lack of knowledge, abilities or achievements
For example, You ask your friend a simple question, but he doesn't have a clue. When you tell him the answer, he says, "Of course I knew. I'd just forgotten!" (He doesn't want to admit that he didn't know the answer at all!)
Or, another example:
You play tennis with your uncle, and he gets creamed! But he says, "Of course I could win if I were younger!" (He doesn't want to admit that his tennis isn't good enough!)