"If he states, "Thou shall not kill," why does he both kill children and commit genocide?"
...*sigh* I told myself I wasn't going to do this, but here we go: As you've already seen, someone made a comment about God existing outside of time. This means he knows everything about everything because He's seen it all. Who you are and who you could be and who you will be. It's already played out for Him.
Now ... about those people that were killed off during Bible times. Do you know what they were doing before they were killed off? Aside from many of them trying to straight up kill off Israel, or trying to convert them to paganism, I mean. Many of the civilizations Israel wiped out--and this is confirmed by secular historians and non-israelite accounts (Egypt, Syria, others I really can't be bothered to remember right this second,)--were very heavily into infant sacrifice.
Do you know what Molech worship is? It's where you heat up the metal hands of an idol until they are red hot, then you place a child in their open hands and let it writhe in agony as it burns to death. Jericho? Put live children into jars, sealed the jars, then sealed the jars in the walls. (I can't really imagine the sound of a baby wailing for its mother until it suffocates to death, but I'm pretty sure I don't want to.) Those practices kind of pissed God off, and according to Bible scholars, that's why God had their walls broken down and most of the people killed. So, if God likes babies, why did he kill off some in other cultures, right?
Well, that's just it. He knew who they were going to be. Israel didn't always wipe out those civilizations as instructed and on occasion, it came back to bite them in the ass, because the remaining children / women often swore revenge and gathered armies against Israel in the meantime--or became part of their culture and tried to get them into stuff like baby-burning. And it worked. Repeatedly. And Israel had a very long period of tug-of-war with itself about following their God vs following idols.
... I guess what I'm essentially saying is, if you look at it from a theist's POV: Your concept of who is / is not deserving of punishment isn't the same as an omniscient being. Our view is a little too narrow from down here.