It is unquestioned that Yanez at least thought that Castile was the suspect in an armed robbery, that he was told Castile had a gun, and that Castile continued to grab for a large object in his pocket after the officer commanded him three times to stop doing so (Yanez stated that he actually saw the gun). Under these circumstances, if it was criminal for a police officer to shoot in what he had legitimate reason to believe was a life-threatening situation, then I would submit that in very short order we would no longer be able to pay good people enough money to become police officers.
But, of course, there is the largely separate issue of whether Yanez did something “wrong” in this situation for which he should be morally condemned by society. This is a much trickier question, but one in which I have been shocked by the lack of rational thought used in trying to answer it.
Obviously, if Castile had no intent to pull out his gun in an aggressive manner, then he didn’t deserve to die. But that is a separate issue from whether Yanez acted correctly/morally.