What you are talking about is the powerful technique of Compartmentalisation. As highlighted in the Wikipedia link I provided here, normally speaking (emphasis mine)
Compartmentalization is a subconscious psychological defense mechanism used to avoid cognitive dissonance, or the mental discomfort and anxiety caused by a person's having conflicting values, cognitions, emotions, beliefs, etc. within themselves.
Compartmentalization allows these conflicting ideas to co-exist by inhibiting direct or explicit acknowledgement and interaction between separate compartmentalized self states (Leary & Tangney, 2011).
Carolin Showers (1992) described compartmentalisation as
the tendency to organize positive and negative knowledge about the self into separate, uniformly valenced categories (self-aspects). As long as positive self-aspects are activated, access to negative information should be minimized.
however, you can consciously compartmentalise negative thoughts, feelings etc.
With regard to hypochondria in your question, compartmentalisation can be extremely difficult for hypochondriacs, as can they have trouble separating personal health facts from false perceptions of their personal health (see Illness Anxiety Disorder in DSM-5 (American Psychiatric Association, 2013) or Merck Manual, or ICD-10 code F45.21).
There are a lot of concepts directly and indirectly related to compartmentalisation, so that part of your question is too broad to answer fully here. However as a start, you could look at secondary trauma (also called vicarious trauma).
Compartmentalisation is often employed, for example, by people within the emergency services (fire officers, paramedics, police officers, coastguard etc.) in order for them to concentrate on the immediate task whilst temporarily isolating themselves from their emotions. Problems can come later for these people if they do not deal with their compartmentalised emotions afterwards during debriefing or clinical supervision sessions.
When studying primary and secondary trauma in medical emergency personnel, Jane Shakespeare-Finch (2011) described this as
adaptive compartmentalizing of emotion during a scenario in which focus on the patient is paramount.
References
American Psychiatric Association. (2013). Diagnostic and Statistical Manual of Mental Disorders. (5th Edition). Washington, DC.
Leary, M. R., & Tangney, J. P. (Eds.). (2011). Handbook of self and identity. Guilford Press.
Shakespeare-Finch, J. (2011). Primary and secondary trauma in emergency personnel. Traumatology, 17(4), 1-2.
DOI: 10.1177/1534765611431834
Showers, C. (1992). Compartmentalization of positive and negative self-knowledge: Keeping bad apples out of the bunch. Journal of Personality and Social Psychology, 62(6), 1036-1049.
DOI: 10.1037/0022-3514.62.6.1036