Weapons are, by definition, crude things. An object whose primary use is to inflict damage does not have to be very technologically complex. Even the most sleek and advanced projectile weapon would look anachronistic in the 23rd century, or in the hands of an advanced alien race, making some sort of direct energy weapon essential for most sci-fi. They were ubiquitous on comic book covers during the golden age of sci-fi.
The first such weapon was the “heat ray” from H.G. Wells’ War Of The Worlds in 1898. That same year also saw the “disintegrator ray” featured in Edison’s Conquest Of Mars, an unauthorized sequel to War Of The Worlds, in which Thomas Edison leads a defense against the Martians, along with other real-life scientists Lord Kelvin and Wilhelm Röntgen, as well as world leaders Queen Victoria, President William McKinley, and Kaiser Wilhelm II.
In 1960 when the laser was invented, “laser guns” became the standard go-to sci-fi weapon, but as the decade progressed, and the public learned more about lasers, it became apparent that lasers were not practical as weapons. That brings us to Star Trek, in the infamous unaired pilot “The Cage,” the side arms that the crew carried were “laser pistols,” but three years later, when the second pilot was filmed, that was changed to “phasers,” based on the idea of the phasing principle of physics, which is a way of increasing power. So a phaser is basically a more powerful laser gun.
Sci-fi technology also gets around a rather sticky problem for a peaceful utopian society like Star Trek’s Federation. In reality, there is no such thing as a guaranteed non-lethal ballistic weapon. Firearm rounds that we traditionally refer to as “non-lethal,” such as rubber bullets and sponge grenades are best described as “less lethal,” and can still maim. But sci-fi technology can do anything you want it to. If a phaser on stun setting does not kill, then it does not kill, simple as that.