there is no inherent reason that these technologies need to be developed by the military, they could just as well be developed for civilian use when given the funding.
also it is not surprising that these things are invented by the dod when you're spending ~600-700 bilion a year on warfare and intelligence operations.
That last sentence of yours rubs me kinda the wrong way; that is a dangerious premise that could set us back ~30 years when the cold war and the arms race was well and alive, but this time we'd have robots and AI