Like Kyoshi said, because we want to feel special. But also because we want to feel apart of a group. In the case of being proud of one's nationality, the rationale would be to fulfil a desire to be a member of something successful. People are proud of their country because of its accomplishments throughout history whether it be innovations, ideas or even victories in wars/competitions against other countries. By openly expressing that we're associated with that accomplishment, we're conjunctively saying, "I'm great because my country is great," (Or something along those lines.)