You're confusing MAD, deterrence and non-proliferation and the ban of weapons testing.
Like first of all using nukes is incredibly stupid to begin with.
Look at the spread of Chernobyl over even western Europe and realize that the neatly contained incident is bullshit. A bit of bad luck with the weather and you might contaminate your own country as well. Or how the nuclear arms tests in the atmosphere still contribute to global background radiation and cancer rates. Not to mention that you should spare a thought of what it means to be on top of the food chain, I mean the literal one, where we eat all the stuff that eats the radioactive stuff...
So since we realized it's not just a "big boom" but also contaminates large areas for long and that we live in a globalized world where things don't stay where they are this should have been plainly obvious...
So yeah don't do nukes, not even once. Not even for testing. No fun to be had for anyone with that.
Now unfortunately that means countries see them as a deterrent like in "If I get a nuke and threaten to use them if attacked then people won't attack me because they might fear, a desperate me might use those nukes just for the heck of it. Genius.".
Let's be real it's still the most pointless weapon to have because you can't really use them and especially small countries often only have short ranged carrier systems so they likely would not just piss in their own pool (harm the planet) but directly on their own feet (harm their own country). So again it's stupid to use them but they somewhat work as a deterrent that way.
Like the next step of insanity is aptly acronymized as MAD. That is the idea of "Yeah but what if we nuke you first and destroy all your nukes?". Well you'd still be living in a world full of radioactive waste that will haunt you for quite some time but you might have won that war. Congratulation king nothing.
However the response to that was "yeah we just build even more nukes and more and diverse carrier systems and all so that you cannot destroy all at once and we still get to destroy all your bigger cities and whatnot and are going to add even more waste and destruction. Genius". To the point of nuclear overkill where you have enough nukes to basically wipe out humanity as a whole and ruin the planet for everyone.
Not to mention that the bomb designs became more insidious with radiation as a weapon and not just as a side effect of "big boom". So like "salted bombs" that would deploy radioactive material with a half-life of 5 years making the area uninhabitable for decades and stuff like that. Many of these doomsday devices hopefully stayed dystopian fiction but yeah that route was not pretty.
And let's be real it didn't really add much deterrence as it was stupid to begin with it just upped the stakes ... like a lot. So yeah a hot war between the US and the USSR would have been something of the end of the world as we know it. Also again it didn't deter shit, the U.S. was still developing missile defense systems and whatnot (don't know if the USSR mirror that as well) to uphold first strike potential and/or survive a first strike. And both sides thought about MAD devices that would auto-fire if attacked (and fingers crossed only then).
But that's about the major players with their world ending arsenals. What about the smaller ones? Well the collective wisdom was "Oh shit, the more nukes in circulation the bigger the chance that some idiot might actually use one". Like suicide bombers exist, so the idea isn't inconceivable. Luckily the development of nukes requires state level funding and resources so again fingers crossed there are not to many "death or glory" fascists who just want to see the world burn or you know terrorists who hijack a nuke...
So usually there was some consensus to not proliferate nukes to non-nuke countries and keep that small. But then the US and USSR also did some imperialism and proxy wars... like a lot... and apparently smaller rogue states thought getting WMDs, including nukes, as a deterrent is a honking good idea.
And there this whole MAD idea works even less... Because idk if Iran starts using a few nukes that's bad. But if the U.S. nukes Iran into oblivion that's even worse. Sure Iran is gone but the rest of the world would be still there just ... you know worse. So for one's own sake you'd probably respond to that conventionally because anything else would just be plain stupid. So MAD doesn't apply here unless they build US/USSR levels of nukes, meaning they could already create enough assured destruction themselves.
Unfortunately the major nuclear powers have set dangerous precedents in terms of attacking countries that give up their WMDs and not attacking those that don't... so ... yeah... they kinda work as a deterrent now. At least for those small states. Which again, remind you, is not good, not only because that allows dictators to mistreat their people without intervention from others but also adds more nukes that might potentially be used.
And now to the actual question of what happens if a nuclear superpower attacks another state with a nuke (nuclear power or not)? Well they'd violate all kinds of international treaties and with a realistic chance of radiation spreading to allied countries or those directly associated with one of the major superpowers you'd have a legit reason to start WWIII (with nukes).
Now would people actually play that game of chicken or even actually end the world? Well we don't know and we hopefully never get close to finding it out!