There is a joke that goes like this;
The richest man in town calls up the local newspaper and complains that he didn't get the store coupons in this week's Sunday supplement. The clerk responds, "Why do you care about the coupons? You're the richest man in town!" Then he responds, "How do you think I got to be so rich?"
Several things come into play in these scenarios.
In Google's case it makes essentially no actual money on "Google Brain", sure it gets headlines for beating Go, sure it attracts top talent (that needs to be paid!) and it still gives those folks free lunches and nice office space etc. So anything that offsets that expense is good.
And in Google, for all of its "lavish" perks, is a penny pincher like our rich man in the story. One of the stories when I was working there, they used to have a brand name juice cases where you could pick up any of the varieties of juice or smoothies that they made. The smoothies were very popular. Then one day out of the blue they swapped them for a different, and by every measure, inferior brand and fewer choices. There were lots of stories about why they switched, but after a lot of internal debate and investigation, the reason was that the replacements were cheaper (by about 25 cents each on their most expensive smoothie as I recall). It angered a lot of employees and one allegedly quit over it (well technically they called it the latest in a string of bad choices). The cost savings, assuming that every employee drank a case of their most expensive smoothie every day (which would represent an upper bound) was about $18M. That was 1% of the quarterly free cash flow (money that had been deposited into cash after all other uses). All of that pain for what was sure less than $18M in "savings".
The third factor is dual use. Sure you can use AI research into interpreting images to build killer robots that can identify and assassinate only those targets you specify. But you can also use it to pick out where the roadway has changed subtly indicating a roadside bomb, or a hazard that a self driving car should avoid, etc.
When you combine these three factors; one that AI team is just overhead, two the corporate willingness to alienate and possibly lose some of their employees over saving a nickel, and the ability to rationalize any number of non-evil uses for the technology, you get a recipe where of course they will sell things to the government without any regard to how that technology will be used. Just look at their main business, selling advertising. They just "sell ads" even when those ads are promoting illegal or unethical acts by consumers whether it is payday loans or Canadian pharmacies. Only when the FTC comes in and tells them to stop do they stop, not through some inner altruism.