You're comparing the nuclear age stealing/selling/sharing of vital state information that can endanger the very existence of a country and it's people with an iron age goat herder worshiping a god other than YHVH...Would you say that a Russian who went to America during the height of the Cold War and sold off state secrets shouldn't be punished since he's just belonging to the "in group"? At the time when the Jewish people were just establishing themselves, with many hostile enemies around them, ideological and religious unity was incredibly important and deviation from it could be dangerous to the continuance of the community. In fact, we see in later history of the kingdoms how - at least from a biblical perspective - this was the result.
On a more general level, do you think it is evil to punish someone for betraying their nation or God?
Sorry, but I don't see how the one meaningfully correlates to the other
That said, even if belief in other gods was a legitimate threat to the Jewish Nation, God could have devised other means by which to protect the burgeoning culture and society of His people - means that did not include a command to kill human beings for the so-called 'crime' of sincerely believing in the wrong god
The only sure fire means by which man can guarantee that a traitor can never again threaten the existence of his/her nation is to eliminate the traitor
There are, however, available to God, an infinite number of means by which to preserve His people without killing the surrounding people
As to your question regarding whether or not it is evil to betray one's nation - I think it depends
As to your question as to whether or not it is evil to betray God - I don't believe that God exists
Something must exist before it can be betrayed
Question for you:
Do you believe that atheists are betraying Jesus Christ?