Many countries require a passport to be valid for six months. Sometimes these six months are counted from the date of departure, or from the date of entrance. Even though some of these countries only legally allow you to stay for 30 days or three months. What is the reason such a requirement is in place in many countries?
When it boils down to it, provided all your travel plans go well, it may not be a problem.
The 6 month limit is possibly a bit long these days, and indeed only some countries insist on it, but it's there, and it's there for when things go wrong.
Every country is trying to get tourists (well, maybe not Saudi Arabia), but to not break the law. You're only allowed into a country with a valid, legal passport, and sometimes a valid visa.
Now, if your passport is expired, suddenly you have an unlawful situation. Your own country effectively says your document is not a valid document. So now said foreign country has someone without a valid document. How do they get you home? Unless you're neighbours, and can just pop across the border, it's now nearly impossible to leave the foreign country, as you'd have to travel through another country which won't accept an illegal document. Indeed, some European countries allow you to return using just a national id card.
Airlines, if they let you travel without a valid visa/passport, are made to bring you back at their own expense. So they won't want to take you either. Indeed for Australia, it's not mandatory that you have the six months, but they warn you that some airlines enforce it, nonetheless.
So now that we have a reason to not allow people to have their passports expire while in the country, why six months? If I'm there for 2 days, and the expiry is 6 months later, why should they care?
First, a lot of the countries that have these limits, offer six month visas. Meaning you could stay right up to the day of departure. So that's one reason.
Now, every day that you get closer to departure risks you having an invalid passport if you overstay even a day.
So for most countries, just having an arbitrary limit aims to prevent this issue. If you're suddenly in a car accident and can't fly out, or, heck, even if your flight is delayed a couple of days, it's best for all involved that nobody's passport expire as a result. Otherwise, legally you become an overstayer, and by law they'd have to deport you, which could be tricky if you're ill. Imagine the situation where you're stricken with, say, swine flu, your passport has now expired, and you get deported. On top of this, you're also considered an overstayer, which will be on your permanent record, and in some the case of some countries will almost certainly preclude you from returning.
Not every country has this six month limit. Many just require you have a valid passport while there. NZ and a few other countries enforce a 3 month rule, although apparently for people from the UK, NZ states that you only need a month free after your visa ends. Each country deals with this in a different way, but the 'six month rule' is common and simple for all involved to understand.