I can't speak for Stanford but MIT is extremely closely tied with the federal government. The Lincoln Lab for instance gets ~$1B/year from the Defense Department. The only reason MIT became a well known institution at all is because of its ties to the military.