God knew before time Judas Escariote would betray Jesus.
"But there are some of you that believe not. For Jesus knew from the beginning who they were that believed not, and who should betray him. And he said, Therefore said I unto you, that no man can come unto me, except it were given unto him of my Father. From that time many of his disciples went back, and walked no more with him." Jn 6:64-66
The scripture was fulfilled ( Psalm 41:9)
"Men and brethren, this scripture must needs have been fulfilled, which the Holy Ghost by the mouth of David spake before concerning Judas, which was guide to them that took Jesus." - Acts 1:16
"I speak not of you all: I know whom I have chosen: but that the scripture may be fulfilled, He that eateth bread with me hath lifted up his heel against me." - Jn 13:18