Can't speak for the whole country, but in California, a 2025 (antigun) study found that among handguns recovered in homicides, 37% were legally possessed and 61% were illegally possessed, with possession status unknown for the remainder.Where are you seeing data that almost all homicides are committed by criminals who illegally possessed the firearm?
Also keep on mind that California homicides clearance rate is only about 55%.