If an ox was rubbing itself against a wall, scratching itself, for example, for its own benefit, it didn’t have any kavanah (intention) to kill a person. But what happened was that the wall fell over and killed a person. Or it tried to kill an animal, but killed a person instead; or its kavanah was to kill an idol worshiper, but it killed a Jew instead; or its intention was to kill a newborn infant. This newborn infant was born premature, and there was no expectation for it to live, so it’s as if it died. Therefore, if it killed that child, the animal wouldn’t be stoned, because it wasn’t a viable baby. But instead of killing that baby, it killed a ben kayama, somebody that would have lived.
In all of these cases, the ox is not put to death because there was an intention to kill the actual victim that they were supposed to put to death for. In the first case, where it was just scratching against the wall, there was no intention to kill at all. In the other three cases, even when there was an intention to kill, the type of killing that the ox wanted to do wouldn’t have necessitated us putting the ox to death: either an idol worshiper, an animal, or a newborn that was born premature. In all of these cases, the animal wouldn’t be put to death. That wasn’t the repercussions for the death of this animal or the other people in this situation.
But if it had the kavanah to kill a Jew and killed a different Jew instead, mashma, it seems to be from this Mishnah, that we would put the ox to death in that case.

