It basically has to do with the fact that it's an international standard, so everyone has one independently of which country they are from. Other types of identification varies between countries, so passports are a nice way to be able to ID everyone who enters the country.
And it's not like you need a passport to enter all countries either. For example, here in Norway we can freely enter most countries in Europe without a passport as long as we have another type of identification, such as a drivers license.
As to why you need identification in itself, it's to make sure that no one enter the country illegally by faking to be someone else.