It’s called projection.
I noticed a curious thing in my early twenties. I had just moved to Atlanta after getting out of the Air Force. I did not know my father growing up, and I was about to start living and working with him.
Turned out my father is a recovering alcoholic. I knew this, already, in the back of my mind. But it didn’t really hit me until after we started spending 16+ hours a day together, that he is a pretty messed up person.
Having been through high school, boot camp, and having had a bipolar roommate, I was no stranger to messed up psychologies. So it didn't really affect me when he started going off on one thing or another.
One of the more curious things I noted about him was that everything he told me about myself that was bad, he himself displayed the undesirable quality to a far greater extent than I did. He wasn't seeing me at all, only himself. He looked at me and saw all the mistakes he had made in his life.
That's what it's like when you criticize. You form a mental model of what somebody else is doing and why. Because you don't actually know that person as well as you think you do, you do what brains always do when they're called on to make decisions with incomplete information. You make shit up and justify it later.
Where does what you're making up come from? Easy, your own life. Your life is the only one that you know in sufficient enough detail to form conclusions from. So you just assume others live the same way you do. What you don't see is the differences that make them unique or that make your judgments invalid.
Once you see this working in real time when others do it, you'll be better equipped to see yourself doing it. This is how you become mature.
If you complement someone sincerely, it means you can actually see a good aspect of someone else. The same principles apply. Sometimes these ‘hit,’ sometimes they don't. A lot of people have complimented me in the past that I can only put down to projection, that person didn't know me well enough to say who I was our what I was about. I just say “thank you” and think nothing of it. Occasionally someone would say something really insightful, that sticks with me.