Normally with aircraft there is a sensor called a weight on wheels switch.
This tells the computer that the aircraft is on the ground.
The computer (or a system of relays for older air frames) will prevent any system that was designated by the owner, or required by regulations, from activating while in the ground.
Also as a secondary preventative measure certain mechanical systems are also pinned in place after landing to help prevent ground actuation.
However if it happened during maintenance it is very likely these systems were disabled to perform system maintenance on the cannon.
aviation.stackexchange.com/users/34917/Darren Dobelman
The article quoted implies that there is a sensor in the F16 to detect when the undercarriage is lowered, which functions as a a gun safety switch, but there is presumably provision for overriding this in order to perform gun testing.
A variety of technical and procedural measures are designed to ensure safety with aircraft gun armament, the details varying with the specific type of weapon.
The M61 20mm cannon will not function without electrical power, it is electrically rotated (when internally mounted) and fires electrically primed ammunition, so switching off the power should prevent accidental firing with this gun.
Other types of cannon with reciprocating mechanisms, such as the 30mm DEFA 550 series have to be cocked or armed before they will fire, a common procedure is to prohibit pilots from doing this until the aircraft is airborne.
aviation.stackexchange.com/users/26711/J. Southworth
There are also physical safety switches, that date back to when weapons were first mounted on aircraft.
Still present on modern armed aircraft.
On the F16, a switch on the joystick controls selection of missiles or gun.
One of it's positions is 'safe'.
Obviously, that switch on the Belgian F16 wasn't in the safe position.
During WW2, there was a real problem with aircraft landing on a carrier, and the guns being discharged accidentally when the jolt of the landing and arresting caused the pilot's hand to hit the trigger on the joystick.
Consequently, landing on a carrier with the gun switch not in the safe position was a serious transgression that would land a pilot in real trouble...
you could kill a lot of deck crew if you discharged six .50 cal machine guns across the deck.
Even so, accidents can happen.
On July 29, 1967, the USS Forrestal was seriously damaged when a Zuni air to ground missile was accidentally discharged from an F4 Phantom, striking an A4 Skyhawk waiting to take off.
Piloting that Skyhawk was a young navy Lt, John S McCain.
While the missile didn't detonate, it did tear open the Skyhawk's fuel tanks, starting a major fire, which led to a 1000 pound bomb detonating.
134 sailors died as a result, and hundreds were injured.
It is believed that a short circuit of the firing mechanism led to the missile being discharged.
Aircraft carriers in particular can be quite dangerous.
They combine high performance aircraft, high speed takeoffs and landings, plus all the fuel and munitions that the aircraft will carry, in a fairly small space.
The fact that aircraft carriers don't blow up more often is a testament to the quality and discipline of
it's crew.
Since the Forrestal incident, there have been no repeats of missiles being accidentally discharged on a carrier deck.
Whatever measures were put in place after that, appear to have been effective.
aviation.stackexchange.com/users/22436/tj1000
According to the article you linked: the use of the onboard weapons (including the gun) is usually blocked by a fail-safe switch when the aircraft has the gear down with the purpose of preventing similar accidents.
It seems it isn't quite so "fail" or "safe", at least in this instance.
aviation.stackexchange.com/users/5517/FreeMan
A lot of fighters have some kind of a "Master Arm" switch that brings the weapons live as well as activates some other related functionality.
As discussed by this former F-15 pilot in the podcast 224 – Flying the F-15 Eagle its flown in the off position 99% of the time .
There is also some discussion about HUD functionality related to the master arm options in this thread (but its Reddit so take it with a grain of salt).
In this article about refueling the F-15 As the fighters approach, they will be asked to “check nose cold andswitches safe.”
That simply means that all emitters are off, toinclude the IFF system, any ECM pods, and the radar is placed instandby mode.
If the approaching receivers were in a fight prior tothe rejoin, it’s critical for them to have their Master Arm switch tothe OFF position and thereby safing any remaining stores aboard .
Depending on the airframe, they may slo simply unload the ordinance to prevent accidental discharge.
aviation.stackexchange.com/users/3677/Dave
Recently the 20mm cannon of an F-16 was accidentally fired on the ground by maintenance personnel at Florennes Air Base in Belgium, resulting the the destruction of another F-16 and damage to a third.  https://theaviationist.com/2018/10/14/f-16-completely-destroyed-by-another-f-16-after-mechanic-accidentally-fires-cannon-on-the-ground-in-belgium/  What measures do  military aircraft have to prevent their weapons from being fired while the plane is on ground?
What measures prevent a military aircraft's weapons from being fired on the ground?
aviation.stackexchange.com
<safety><military>
aviation.stackexchange.com/questions/56064
aviation.stackexchange.com/users/34916/Argenti Apparatus
A variety of technical and procedural measures are designed to ensure safety with aircraft gun armament, the details varying with the specific type of weapon. There are also physical safety switches, that date back to when weapons were first mounted on aircraft. The crew also ensure weapons are not fired.  To begin with, a typical measure taken is a sensor on the aircraft. Moreover, techical, procedural and mechanical measures are taken depending on the weapons that are carried by the aircraft. As for some specific types of weapons, switching off the power of the military aircraft is enough, while for other types of military aircrafts there are physical safety switches in the form of  joysticks or "master arms". Finally, an important measure of protection is  the quality and discipline of the aircraft's crew, since the pilots are prohibited to arm cannons that work with reciprocating mechanisms.
A typical measure is a sensor on the aircraft. Techical, procedural and mechanical measures are taken according to the type of the weapon. Switching off the power of the military aircraft is enough for some cannon types. Physical safety switches in the form of a joystick or a "master arm". An important measure of protection is  the quality and discipline of the aircraft's crew,  since the pilots are prohibited to arm cannons that work with reciprocating mechanisms.