I was also going to suggest empathy. A recent article on neuronal correlates of empathy (as well as something called theory of mind) concludes:
”[Theory of mind] stimuli revealed increased activations in lateral orbitofrontal cortex, middle frontal gyrus, cuneus and superior temporal gyrus. Empathy, on the other hand, was associated with enhanced activations of paracingulate, anterior and posterior cingulate and amygdala. We therefore suggest that [theory of mind] and empathy both rely on networks associated with making inferences about mental states of others. However, empathic responding requires the additional recruitment of networks involved in emotional processing.”
Mirror neurons may also be relevant, although they’re not exactly the same as what you’re describing. These are neurons that fire both when you perform a certain act and also fire when you see someone else perform that same act. If you’re interested in reading more, here is a lengthy but informative review article.