God gave His created beings free will - we can obey Him or disobey Him, love Him, ignore Him, or even try to work against Him. He could have created an army of obedient robots, but He didn’t. In giving us the choice to love and serve Him, He knew that would mean that some would ignore Him and others would turn against Him.
I think of this in terms of my own children. Nothing means more to me than when their faces light up and they run to me and throw their arms around me. That would mean nothing to me if their only option was to obey and love me.
God gave us options, knowing that one of those options is betrayal.