There are several partial answers rather than one simple one. In the United States, the convention of guns firing Sci-Fi laser bolts instead of bullets was a mixture of self-censorship by the studios, voluntary agreements by the broadcasters, regulation by the Federal Communications Commission, and pressure by watchdog groups on stations through their advertisers.
Toy Guns Got Kids Shot by Police
Several lines of toys were canceled because a police officer shot a teenager for playing with one, and at least one cartoon in the 1980s was killed off by this directly, and perhaps one indirectly.
This happened in 1987 to a 19-year-old with a toy Lazer Tag gun, which was designed to look acceptably futuristic. The cartoon made to sell the toy guns was swiftly cancelled.
Em 1988, a series of realistic-looking water guns (“The Look! The Feel! The sound! So real! Entertech!”) led to three teenagers getting killed by police who mistook their toy squirt guns for real guns. While the convention of not depicting bullets in cartoons had been established by that point, this led to a ban on realistic-looking toy guns and made merchandise-driven cartoons even more leery of anything that could lead to bad publicity.
Although there was no Entertech cartoon, the parent company also was making The Bionic Six. Although that cartoon did not feature guns, it was stranded when its owner decided to get out of the toy business.
Letter-Writing Campaigns
In the late 20th century, a number of concerned parents (generally older, conservative, Christian moms) formed watchdog groups to watch children’s television and complain to anyone with leverage over the shows’ production, including the networks, local television stations, their advertisers, politicians and the FCC.
O Dungeons & Dragons cartoon you mention has several good examples, in part because there was a panic at the time over (inaccurate and sensationalized) reports that the game it was based on led to Satanism and suicide. Mark Evanier, who wrote the pilot and the premise, remembers:
As you may know, there are those out there who attempt to influence
the content of childrens' television. We call them "parents groups,"
although many are not comprised of parents, or at least not of folks
whose primary interest is as parents. Study them and you'll find a
wide array of agendum at work…and I suspect that, in some cases, their
stated goals are far from their real goals.
Nevertheless, they all seek to make kidvid more enriching and
redeeming, at least by their definitions, and at the time, they had
enough clout to cause the networks to yield. Consultants were brought
in and we, the folks who were writing cartoons, were ordered to
include certain "pro-social" morals in our shows. At the time, the
dominant "pro-social" moral was as follows: The group is always
right…the complainer is always wrong.
This was the message of way too many eighties' cartoon shows. If all
your friends want to go get pizza and you want a burger, you should
bow to the will of the majority and go get pizza with them. There was
even a show for one season on CBS called The Get-Along Gang, which was
dedicated unabashedly to this principle. Each week, whichever member
of the gang didn't get along with the gang learned the error of his or
her ways.
We were forced to insert this "lesson" in D & D, which is why Eric was
always saying, "I don't want to do that" and paying for his social
recalcitrance. I thought it was forced and repetitive, but I
especially objected to the lesson. I don't believe you should always
go along with the group. What about thinking for yourself? What about
developing your own personality and viewpoint? What about doing things
because you decide they're the right thing to do, not because the
majority ruled and you got outvoted?
We weren't allowed to teach any of that. We had to teach kids to join
gangs. And then to do whatever the rest of the gang wanted to do.
What a stupid thing to teach children.
Another writer on that cartoon who also remembers the writing staff as constantly pushing the limits is Michael Reaves, mentioning that an episode where the children consider killing the bad guy (and decide not to) almost did not get aired.
One example from the ’80s directly relating to depictions of gun violence was Capitão Poder e os soldados do futuro. In 1988, the show hired Carole Lieberman, a psychologist who had written to complain about its premise ("The image of a kid coming home to an empty house, sitting in a dark room and shooting at a television set is a very disturbing one.") and, although it wasn’t about to abandon its entire raison d'être, selling toy guns to kids, it did announce that it would cut the length of all its laser-gun battles thereafter.
In 1990, the vice-president of Western International Media disse O LA Times, “[B]ig advertisers are so afraid of their letter-writing campaigns that they sometimes don't think it's worth the effort to fight (such activists), even if there is a big rating at stake.”
Although the writers and grown-up fans of old kids’ television tend to remember these groups as prudish busybodies, it’s important to remember where they were coming from and that they weren’t always wrong.
The mass media were completely different before streaming video, cable TV, or even home video. There were three national networks in 1980, which needed to avoid offending anybody, plus public TV and maybe a couple of local UHF stations that syndicated reruns and played old movies. If you look at the records for what programs had the highest percentage of Americans watching them together, the records from those days are unapproachable and might well stand for all time: if all the networks decided that they had to air a Presidential debate, there was literally nothing else to watch, and no Internet. Until Star Trek: The Next Generation, there were no big-budget shows in first-run syndication. Most of the time, there were no programs for kids on any station, but everything needed to be family-friendly. And kids before the Internet, or even personal computers, grew up watching a lot of TV. The courts had held that the First Amendment did not prevent the government from regulating the contents of broadcast TV or radio, because there were only a limited number of radio frequencies that could never fit more than about half a dozen TV stations, and therefore that limited resource must be licensed in the public interest. What kids’ shows there were were totally funded by advertising or merchandising.
Today, when we read that Action in Children’s Television in 1970 wanted the government to ban all TV ads aimed at kids and make all stations air fourteen hours of ad-free educational programming a week, that sounds quaint—at best—because the context in which it made sense is dead and buried. But, at the time, more than one hundred thousand letters “filling 63 dockets” were sent to the FCC supporting it. And that misses a lot of nuance. ACT (along with a few others, such as Fred Rogers, who gave the keynote address at its First National Symposium on Children and Television in 1970) did at least force networks to think about the messages they were sending kids, not just the ratings, and pushed for children’s programs to aspire to more than selling toys and high-fructose corn syrup. They advocated for programs to be made for different age groups, to have the stories be about age-appropriate problems, to be less stereotypical and formulaic, and even to stop using so many idiot plots. At times, it joined with the ACLU to defend the free-speech rights of broadcasters (because the government had declared their self-censorship to be illegal, and politics makes for strange bedfellows).
Not all of these activists demanded that violence be unrealistic. Some said at the time that that was worse. For one contemporary perspective on that debate, Nicholas Johnson of the FCC, speaking to ACT’s second national symposium in 1971, said:
But programming content is an area that government ought to be
extremely reluctant to enter—and one that anyone will quickly find is
a quagmire. How does one measure the “quality” of a children's
program? And if the judgment is only subjective would even those of
us here agree on which programs we would, and would not, permit?
Do you want to forbid the showing of any violence?
Or are you simply concerned that it be shown realistically, rather
than as painless fun? Or, on the other hand, would children be
unfavorably affected by such realism? What if the problem is that
those who write children's programs are devoid of the imagination and
creativity necessary to write interesting material that does not
contain violence? If that is the case, when the violence is removed
the program that remains is even more vapid and mind-rotting than it
was before. Maybe the solution is to train better writers.
Self-Censorship
In 1952, the same moral panic that led to the creation of the Comics Code Authority led broadcasters to testify before the Congressional Subcommittee on Juvenile Delinquency as well, and use the same strategy to avoid a censorship law: voluntary self-censorship through a board they themselves controlled. The National Association of Broadcasters, which included all the national networks, voluntarily adopted a Code for Television, with a number of special provisions for children’s programming. There was a similar move by a smaller association of independent stations. Like the Comics Code, this was based on the Hayes Code for movies, and like them, it banned any content that was deemed unsuitable for children in the 1950s. (The present system of rating content for age-appropriateness would not come to movies for another decade and a half, or TV and comics for half a century.)
Its provisions included:
The presentation of techniques of crime in such detail as to invite imitation shall be avoided.
The use of horror for its own sake will be eliminated; the use of visual or aural effects which would shock or alarm the viewer, and the detailed presentation of brutality or physical agony by sight or by sound are not permissible.
This wasn’t interpreted to ban all depictions of guns, bullets or people being shot. There is an additional section on shows for children, which adds:
[...] avoiding material which is excessively violent or would create morbid suspense, or other undesirable reactions in children.
This was the era when a Jornada nas Estrelas script called for Spock to knock an enemy out by hitting him over the head with his phaser rifle, and Leonard Nimoy complained to the director that this was a cliché of TV westerns. (Hollywood’s portrayal of concussions as no big deal has caused a lot of harm itself.) Wouldn’t the advanced civilization of the enlightened future have thought of something better than using a phaser like a caveman's club? So he suggested that maybe an alien could know some kind of Vulcan nerve pinch instead.
Similarly, it was the NAB that in the 1970s prohibited the hosts or heroes of kids’ shows appearing in television ads that ran during the program.
The code had no legal force, but only stations that followed it were allowed to advertise that they were certified for their good behavior, and all the networks did. It was abandoned in 1983, but stations and studios continued to have Standards and Practices boards to decide what was and wasn’t acceptable.
Intervenção governamental
The FCC did have the authority to regulate what was broadcast on television (and courts had upheld it), but it almost never used it. Indeed, it was the government that forced the networks to abandon what standards they did have in 1983, on the grounds that agreeing to limit advertising on children’s TV shows was illegal collusion in restraint of trade. The Reagan administration strongly supported deregulation and considered most content restrictions, such as the Fairness Doctrine requiring political balance, to violate the Constitutional right to free speech. (With exceptions such as laws against pornography.) And that is why “30-minute toy commercials” like He-Man e os Mestres do Universo, Os Transformers, My Little Pony e GI Joe began appearing in 1983 and 1984. Before then, TV stations were not allowed to air them.
There were no meaningful cases in the 1980s of the government having to step in and censor a children’s show. All the real limits were imposed by self-censorship or by pressure from advocacy groups. The first significant legislation was the Children’s Television Act of 1990, which put back some limits on advertising to children and required some amount of “Educational and Informative” programming.
They Weren’t (Always)
Sometimes, kids did get to see a realistic gun. Most famously, a Japanese robot that transformed into a realistic-looking Walther P38 and fired toy bullets became the cartoon villain Megatron. Nor is that the only questionable aspect of the design.
A version of this toy has been mistaken for a real gun at least once: on June 3, 2009 in Windsor, Ontario, a 25-year-old man (who would have therefore been a few months old when the cartoon was broadcast) waved around his Megatron and his aunt called the police. His friend would later tell the press, “It’s a Transformer. It turns into a Luger. It’s an 80s-style Transformer... He’s had a really bad day. People are treating him like crap.” The woman living next door was less sympathetic: “I’m the one that drove him home from the hospital, for crying out loud. I don’t know what the hell his problem is with me.” According to the Windsor Star, “The three-hour standoff forced the lockdown of a nearby elementary school, and drew a police response that included tactical officers, body armour, submachine guns, sniper rifles, a police dog and the mobile command centre.” Fortunately, no one was injured.
An updated version of the toy is still being sold to collectors, but all toy guns sold in the United States and some other countries now are legally required to have an orange cap. The character (or a namesake) has been redesigned several times as a tank, plane, car and Tyrannosaurus Rex.
There were plenty of programs at the time that showed people firing or being shot by guns. In fact, one study of violence on TV around the turn of the century found that The Family Channel had the most gun violence of any broadcast or cable channel, because of all the old Westerns it aired. One cartoon from that time that had both heroes and villains use guns (in the opening credits, no less) estava Robocop, since that was based on a R-rated movie.
A more serious example was the Gárgulas episode “Deadly Force” from 1994, in which one of the Gargoyles starts playing with his human friend’s gun, imitating the Western movie he watched earlier in the episode, and accidentally shoots her. The consequences are portrayed realistically. She needs to go to the hospital, have an operation, and heals from it over the course of several episodes. This was taboo-breaking for a Disney cartoon. Within a few years, TV programs would display an age rating for “Violence” or “Fantasy Violence” instead of banning it. It makes as good a moment as any to call the end of the era.