Your brain is designed to protect you from painful thoughts and emotions by keeping them out of your conscious awareness.
Sigmund Freud first identified nine psychological defense mechanisms, also called ego defenses, and many psychoanalysts have added more over time.