It is a ego defense mechanism (never really got into psychodynamic psychology) that is meant to alleviate cognitive dissonance, which is psychic pain that occurs when our thoughts and actions do not comport with the mental image we have of ourselves. In projection, you take a behavior or trait which you possess, and assign or "project" it toward others (usually people you dislike).
The perfect example is the conservative obsession with illicit sexual activity (bestiality, pedophilia, etc...) which they try to blame on LGBT people, but are often caught engaging themselves (think Hasteret, Foley, Trump, and now Gaetz).
Preachers blame the collapse of society on "liberal" fornication, then are caught having affairs themselves ala Jimmy Swaggart, Jim Baker, and that fool from Liberty University that I am forgetting the name of.
Conservatives are very fond of projection as their go to defense mechanism.