Why is Earth's climate so stable?
The Earth's climate isn't quite as stable as you think. The Earth's climate has toggled back and forth between a greenhouse Earth and an icehouse Earth for the last 600 million years or so. During the icehouse Earth phases, the climate can enter an ice age, an extended period of time during which the climate in oscillates between glaciations and interglacials. We are currently in the midst of an interglacial period of an ice age. On the flip side of the icehouse Earth climate, dinosaurs and tropical plants lived close to the poles when the Earth was in a greenhouse phase.
In the past, there was a third climate phase, snowball Earth, which made the icehouse Earth look mild in comparison. Even during the worst glaciation, ice rarely reached closer than 40 degrees latitude of the equator. During snowball Earth phases (that last of which ended over 600 million years ago), ice reached well into the tropics, and possibly all the way to the equator.
One of the open issues in paleoclimatology is explaining why the early young Earth wasn't perpetually stuck in the snowball Earth phase. The Sun's luminosity has been growing in intensity since it formed. Sunlight was only 75% to 85% as intense when the Earth was young as it is now. So why wasn't the Earth permanently frozen long, long ago? Explaining why this was not the case (and geological evidence says it wasn't) is the faint young sun problem.
Regarding Mars, that's fairly simple. Mars is too small. Mars's core froze long ago Mars magnetic dynamo stopped operating long ago, and if Mars ever did have plate tectonics, that process stopped long ago. The end of plate tectonics stops any outgassing that would otherwise have replenished the atmosphere. That Mars is small means it has a tenuous hold on its atmosphere. The loss of a magnetic field (if it ever had one) would most likely have exaggerated the atmospheric loss, particularly if this happened when the Sun was young and had a much greater solar wind than it has now. The combination of the above means that even if Mars was habitable long, long ago, that habitability was rather very short lived.
Regarding the giant impact hypothesis, you have it exactly backwards. Look to our sister planet. Venus has a very thick atmosphere and as a result has surface temperatures higher than those on Mercury. The giant impact hypothesis offers one explanation for why Earth is not like Venus. If it wasn't for that impact, the Earth would still have a thick primordial atmosphere and we wouldn't be here. Our planet would be uninhabitable. Mars would be habitable if it was the same size as the Earth or Venus and if it had a Venus-like atmosphere.
Update: Regarding Anthropogenic Global Warming
A number of comments has taken this answer to be proof that anthropogenic global warming is not happening. To the contrary, it most certainly is happening.
As an analogy, consider a farmer who takes a trip to the Grand Canyon, then Badlands National Park, and then the Channeled Scablands in eastern Washington state. The farmer can rightfully conclude that nature has destructive capabilities that can far outdo even the very worst of farming practices. He cannot however conclude that poor farming practices do not cause erosion based on the existence of those remarkable records of natural erosion.
The extent to which anthropogenic global warming is happening and what that means to humanity -- that's a different question and should be asked as such. What the long term variations in the Earth's climate as described in this answer mean to humanity, well that too a different question.
A slightly simpler version of David Hammen's (as usual excellent) answer:
- Earth is "big enough" to have sufficient pull on the atmosphere: gravity stops it from escaping
- Earth is "close enough" to the sun to keep liquid water (and liquid core)
- Core is sufficiently magnetic that it acts to protect against solar wind (which would otherwise strip the atmosphere over time)
- Earth is "far enough" from the sun to keep liquid water
- Earth's atmosphere is "thin enough" (after the giant impact it lost some atmosphere) that the atmosphere doesn't act as a suffocating blanket (unlike Venus)
All of the above made conditions for life to evolve "just right" - we live on a Goldilocks world*. Which is why we humans are (still) here and wondering why our planet did so well. It's not that we are lucky we evolved on the third rock from the sun - it's that only the third rock from the sun had the right mix of conditions for us to evolve.
* For those who do not have an English-speaking background/upbringing, Goldilocks is the girl from the story who went to the house of the three bears, and tried their food, chairs, bed... finding the first one too hot / hard etc, the second too cold / soft etc, and the third "just right". It has led to using "Goldilocks" as a metaphor for "the right value between unacceptable extremes".
The main reason Earth still has its water and Mars doesn't is gravity. Earth is big enough so that typical thermal speeds of hydrogen in the upper atmosphere don't get to escape velocity. On Mars, this is not the case, Mars having significantly less mass and therefore lower escape velocity. As a result, over a long time, much of the hydrogen that was originally on Mars has evaporated into space.
Since ice doesn't evaporate into the atmosphere much, we expect there could still be significant deposits of ice on Mars.