The death penality is abolished in Germany. Wouldn't it be prudent to also outlaw the killing of criminals in danger situations when it would be possible to stun them efficiently in the same time?
The difference is that when someone is arrested, tried and convicted, the convict poses no danger to society anymore. So, not having the death penalty saves lives (note that studies have shown that there is no deterrence effect from having the death; murder rates are not lowered by virtue of having the death penalty).
In case of a situation where a gunman poses an imminent risk to people, the situation is different, eliminating the risk posed to the people takes priority over saving the life of the gunman. However, even in such a situation, the police will still try to resolve the problem without having to use deadly violence.
The main reason is that "stunning them efficiently in the same time" is often not possible. The tools available to the police (pepper spray and baton) are far less efficient than firearms. They have a much shorter range and sometimes fail to incapacitate an attacker where a firearm would be successful. A police officer is only supposed to use deadly force when the life of the officer or of a civilian is in danger. In that case it is a case of self-defense (which is the right of every citizen when their life is threatened), not a government-sanctioned execution.
There are discussions in some federal states to equip police officers with electric shock weapons (aka "tasers") to "close the gap between baton, pepper spray and handgun".
Proponents of this say that this could reduce the number of deadly use of firearms by giving police officers an alternative way to incapacitate a dangerous attacker.
Opponents point out that in countries where police officers are already equipped with electric shock weapons, officers frequently abuse them by causing unnecessary pain to suspects which could be subdued in other ways (not necessarily representative example: the "don't tase me, bro!" incident at the University of Florida in 2007) and even for torture. This kind of police brutality is hard to prosecute because electric shock weapons rarely leave lasting marks. Also, electric shock weapons can endanger the life of suspects with heart conditions, in these cases, they are not as harmless as expected (Amnesty International claims US law enforcement officers killed over 500 people with them between 2001 and 2012).
In countries where the police are armed, the police normally want to retain their guns, as it offers leverage when facing violent criminals.
In countries where the police are not routinely armed, the police normally want to stay unarmed, as it is felt that carrying guns will lead to more criminals also carrying firearms.
There seems to be a resistance to change. Both styles of policing can be effective.
Your premise is wrong. Police officers are already trained to use non-lethal force whenever possible. However, there are still situations where less violent options are far more likely to endanger the officers or civilians and thus using a gun is the prudent option, which for that reason is not being outlawed. That being said, also note that using a gun isn't necessarily a death sentence - it depends again on the situation whether a warning shot, a shot to cripple an attacker rather than fully incapacitate (likely kill) him/her is the best option.
However, whether all officers need to carry a gun is a viable question, some countries seem to fare well with having only special forces carrying guns.
Police carry weapons in order to compel compliance from potentially hostile people, and to protect themselves.
They don't carry it to disburse mini-punishments to the unlawful or unruly, so the context of what the laws have as punishment for conviction should not be relevant. The police are only supposed to use lethal force to protect themselves or other citizens from a life-threatening situation. It's considered that erring on potentially using too much force and killing the person who has made themselves a lethal threat is preferable to erring on being too gentle and the police or an innocent bystander getting killed by a perpetrator.