If there are gun deaths, you could fight that directly by taking away the guns.
Kinda like how you can prevent vaccine deaths by outlawing vaccines? I mean yea that will objectively reduce deaths from X by outlawing X.. but like with guns that also prevents “lives saved indirectly by X by outlawing X”. Which as you point out is exactly like guns, sure outlawing them will reduce deaths directly from guns, but then causes a much larger increase int he deaths from all the things guns help prevent (like rape).
Or you could look at consequences and make it undesirable, not naming and faming mass shooters in the media is one puzzle piece.
I mean, yea having consequences for bad acts and not rewarding it is certainly one good take if applied correctly. But these are hardly your only two options. Take guns for example, we dont have a gun problem we have a murder problem (of which guns are used a small fraction of the time). So there are plenty of preventative measures one could take that doesnt have the consequence of causing people to die en masse like restricting gun access is known to do. For example providing better mental health and societal dynamics so fewer people become murderers to begin with.