defense mechanism.Basically, your brain is already trained to compartmentalize. It the “fight” mechanism that your brain adopts in case of stress and anxiety.Whenever two clashing emotions or thoughts come face to face, your brain pushes them away and puts them in two different places.
Your mind keeps contradicting thoughts away to keep you at peace.This is exactly what compartmentalization is.However, it is suggested to use this mechanism before the clash actually arises.
Read more on lifehack.org