There is no advantage to an AI to wipe out all humans so why would it choose it?
The difficulty here is in wording the goal. There is a really good explanation on the wait but why AI post linked above. But in short if the AI's goal is to find the most efficient way to create paperclips for example, it could potentially and eventually get so smart that it's just turning all matter on earth into paperclips. Let's say we thought about overproducing paperclips and set the goal instead to be for the machine to produce as many paperclips as humans need in real time, based on evaluating previous usage and predicting future usage. Well, the most efficient number to produce is 0. So it's actually in the machine's interest to ensure that nobody needs any more paperclips ever again. It could just create another machine to create paperclips for it, or invent something that means paperclips are obsolete. But the simplest way to ensure that humans don't need any more paperclips is probably just to kill all the humans.
We can't just tell it not to harm humans because what does that even mean? We don't really understand morality very well ourselves let alone being able to explain it to a machine that doesn't understand humans. You could tell it to prevent human suffering and actually the most efficient way for it to do that would be for it to kill everyone. So you can tell it explicitly not to kill anyone, but in order to eliminate suffering it just kind of unplugs everyone's brain. No more suffering, but no more anything either. We think it's obvious that no suffering meant that we still want to experience all the nice things about being human, but that's not obvious to a machine that only understands literally exactly what you tell it.
Language is full of assumption and shared understanding, most of which is very cultural and learned. Culture and learning that a machine would not have and we take for granted so would not be able to program it in.
People have strange ideas about what AI might be, they think of it as like an intelligent animal, like you can teach crows to do simple puzzles. Or they think it's like teaching a child, not really understanding that we only directly teach children a fraction of what they learn, most of their learning is primed in the brain and comes from experimentation having been honed through evolution (with lots of death along the way). Think about all the daft experiments that toddlers like to do that could get them killed or harmed or other people killed or harmed if they had more body strength, ability to manipulate computers, or adults weren't around to stop them.
Or they think AI is some malevolent force like a movie villain who just wants power. That's a very human interpretation, it's unlikely that AI would "want" this - but it's possible that AI might see power as a means towards some other goal in a way that we fail to predict.