In the Old Testament, the prevalent view among the people (of Israel and its surroundings) is that their gods controlled each of their land. A war between nations is simply a war between their respective gods. Those who won the war showed that their gods were more powerful than their beaten enemies. Thus it is perfectly normal for Ahaz, King of Judah, to offer sacrifices “to the gods of Damascus, who had defeated him; for he thought, ‘Since the gods of the kings of Aram have helped them, I will sacrifice to them so they will help me.'” (2 Chr 28.23) It is still wrong, but it does make sense. If you can’t beat them, you join them.
What’s bewildering, then, is the response of Ahaz’s great-grandfather, Amaziah, after he defeated the Edomites. For it is written, “When Amaziah returned from slaughtering the Edomites, he brought back the gods of the people of Seir. He set them up as his own gods, bowed down to them and burned sacrifices to them.” (25.14) And that’s why a prophet was sent to Amaziah, and he asked incredulously, “Why do you consult this people’s gods, which could not save their own people from your hand?” (25.15)