Sure, that could happen but expanding to Mars would improve the odds of survival (because an extinction event on both planets simultaneously is less likely than one just on Earth). Earth is currently a so-called "single point of failure" (SPOF)[0] for humanity and all forms of life that we know of.
If we spread humanity and life to Mars and beyond (in an independent/self-sustaining way and not just as an outpost that depends on Earth), neither of the planets alone is SPOF anymore. The solar system is still SPOF but even the close galactic neighbourhood might not be of much help against events that threaten the solar system as a whole (see e.g. about the effects of a gamma-ray burst [1] in our 'proximity'. Note when reading [1] that 1 kiloparsec = 3200 light years! [2]).
[0] https://en.wikipedia.org/wiki/Single_point_of_failure
[1] https://en.wikipedia.org/wiki/Gamma-ray_burst#Effects_on_Ear...
In Bradbury's story, the vast majority of residents of the Martian colonies returned back to Earth when (atomic) war was imminent, leaving Mars all but deserted, and the Earth destroyed.
I found this hard to believe, but this set up a really cool ending.
The problem is that would grant like 30 years of safety. Maybe. Not much more, but could be enough.
The best argument is that frontiers are where innovation happens, and where outsiders can migrate as a "pressure valve" for civilization. Without a frontier there is nowhere to try new things and it's impossible to challenge existing norms without fighting. No frontier means either eternal stagnation or eternal war. (War can take the form of either overt violence or constant political turmoil.)
https://en.wikipedia.org/wiki/Frontier_thesis
I don't think it's a coincidence that sci-fi that posits a frontier (generally space but sometimes others) is usually more optimistic than sci-fi that posits a humanity confined to Earth's gravity well. Writers and artists see this.
We are rapidly approaching a state in which the entire planet is settled, surveilled, and regulated. This is unprecedented in human history, and I think it's going to be fairly dystopian. I can only see two possible outcomes: absolutely total global surveillance state or a global "failed state" resembling a dystopian cyberpunk anarchy like Stephenson's Snow Crash. They're not mutually exclusive; the first could lead to the second.
I don't think it's feasible to reverse this trend. It's a natural outcome of humanity's growth and technological advancement. Pushing out to a new frontier is really the only option.
Anyhow, what are we talking about here? Why did the topic of Mars and avoiding nuclear armageddon come up?
If we could prove beyond shadow of a doubt that no dangerous asteroids would hit Earth for a million years and that pursuing Mars accelerated our environmental problems here, I don't doubt that the same people would come up with new justifications and keep going, even if counterproductive.
It's about a very selfish 1st world problem:
Seeking thrill and also not to be discounted the willingness to feel special. Everyday we see and interact with so many people, we have also internalized the concept of being one unit in a 8B sample and that hurts our ego as we want to feel unique and irreplacable.
People hope to find that in a small Mars community, feeling irreplaceable both on a conceptual level as well as a practical level (meaning for the operation of the colony).
War on Mars will also be something else. Canadians understand this all too well. You're far enough from everything to make you not a target. Life on Mars will be precarious for everyone far worse than the mutually assured destruction that prevents it happening on Earth.
It doesnt eliminate all issues, but it certainly eliminates lots of issues.
For the Earth, Mars, and Asteroid belt conflict, watch "The Expanse".
Your question, I assume, is based on the idea that humans may well colonize Mars and one of reasons for doing so is to increase humanity's chance of survival an otherwise extinction-level event.
It's worth pointing out that nuclear war is just one of many potential extinction level events. Even then, nuclear war in particular is unlikely to exterminate the entire species. Another where colonizing Mars would help is, say, a massive body impacting Earth.
But stepping back, colonizing Mars is largely a romantic notion, not a logical one. People imagine themselves walking on Mars but there are severe problems with this:
1. Gravity is much lower than Earth. It's roughly similar to the Moon. It's unclear how we'd deal with living in low-gee like this on an indefinite basis;
2. Mars has an atmosphere but it's actually worse than no atmosphere in many ways. It's barely above vacuum so you can't breathe it, even if it was the right gas mix (which of course it isn't). All it really does is stir up dust to cover all your above-ground installations. Solar panels are likely to be one of these so you can't really avoid it. Dirt and dust on Earth have been eroded by eons of wind and water. Not so on Mars. Martian dust is jagged and "sticky" as a result. So it's more annoying.
3. Mars has no protection from solar radiation unlike Earth (ie the Van Allen belt / magnetosphere); and
4. Even though gravity is lower, getting into and out of the gravity well is still a considerable issue, particularly given the lower atmosphere doesn't have the same potential for aerobraking as Earth's atmosphere does.
For nuclear war in particular, a political entity may well also exist on Mars that will make a nuclear strike. You'd likely get more warning since Earth's superpowers have quick strike capability from nuclear attack submarines that can be positioned off the coast of major cities. Mars of course has no oceans so you're talking air or ground vehicles or ground installations.
Nuclear missiles could come from Earth but you'd get a lot of warning for this (weeks to months) and this wouldn't be cheap.
Personally I'm convinced the future of spacefaring humans is in orbitals not on other moons or worlds.
So it's more a signifier of diaspora on space than about a single Mars city
Uniqueness does not make something useful or worth preserving, either.
As individuals, we all expire at some point. Is there a reason to think that humanity should be any different?