There are numerous examples in the Bible of people doing wonderful things, including knowing things that they could not know by themselves.
For example, Ahijah knew the king’s wife, even though she was disguised and he was blind (1 Kings 14:6). Daniel knew what Nebuchadnezzar had dreamed, even without being told (Dan 2:30). Peter knew Ananias was lying(Acts 5:3).
In all these cases it is the power of God that grants them these abilities. Jesus is no different, he was given power from God to perform this kind of miracle (Matt 9:8, 21:23-27; John 5:19, 30, 9:33).