It seems surprising that Jesus, the omniscient Godhead in bodily form (Col. 2:9) would ask from a mortal man whom he foreknew and predestined (Rom. 8:29) before He could find out how long an ailment has troubled the young boy. Does that suggest that Jesus did not know about the boy's situation?
A somewhat similar question He asked the blind Bartimaeus in Mark 10:51: "...What do you want me to do for you?" but this may be explained that the question was asked perhaps to offer blind Bartimaeus the right of making a choice of what he wants as a free moral agent.
However, in the case of Mark 9:21, it sounds as if it was a question deliberately asked in search for an answer for something that appears not to be known before.
Hence, my question: Why did Jesus ask the father of the boy with unclean spirit: “How long has this been happening to him?”