Facing a wave of criticism for allowing advertisers to exclude anyone with an “affinity” for African-American, Asian-American or Hispanic people from seeing ads, Facebook said it would build an automated system that would let it better spot ads that discriminate illegally.