Off course he would know. Sure, God can't do anything (e.g. He can't go to hell). Let's say you have an equipment (e.g. a machinery), which no-one in the world has ever seen before. Who is the first person to know how this machinery works and what its mechanism includes? The answer would be the manufacturer, creator, inventor or the producer. Now God is the one who created pain in the first place and so obviously God knows what he has created. We have a limit to our pain and we have pain tolerance, so if God didn't know what pain is he wouldn't be able to make us pass out or lose awareness after we've exceeded our pain tolerance.
There is no randomness when it comes to religion, everything is done under God's command. When I crash my car into a tree it's not random, but it is the will of God. One of God's names in the Qur'an is Al-Bari (=The Evolver). Meaning that even adaption and evolution happens under God's command.