pull oneself together means calm oneself down and begin to think or act appropriately. I am wondering how they are relevant and how to understand it?
If you want to better understand the idiom pull oneself together, I'd suggest that you rather think of the opposite expressions to fall apart and to break down. When you break down, what typically happens is that you become overemotional, lose control over yourself and start crying. So, when you're about to emotionally begin breaking down, what you want to do is to calm down, get a grip and start pulling yourself together. Think of a car or other mechanical device that breaks down after a period of extensive use. When it breaks down, it starts falling apart to pieces and in order to fix it, you need to pick those pieces up and put them back together (instead of put, think pull).
I was about to break down in tears when I heard the sad news that he died, but instead I calmed down and pulled myself together because since my early childhood I was taught that no matter how terrible life sometimes can get, real men should never cry.