Just to add.
You have to remember that ‘monotheism’ for the ancient Israelites was quite close to what could be called henotheism (worshipping and believing in a single god while accepting the existence or possible existence of other deities, who may or may not be also worshipped).
The common idea in those days was that each nation or city had its own chief patron deity: Yhwh for example is the national God of the Israelites, Chemosh is the god of the Moabites, Moloch/Milcom is the god of the Ammonites, Qos is the god of the Edomites, Melqart is the god of the city of Tyre, Eshmun is the god of Sidon, etc. There was no separation of religion and state in those days, mind; the state religion is closely tied with the government. So basically worship of the national god is key to national identity.
While official orthodox Israelite religion - as represented by the priests of the Jerusalem temple and the prophets - taught that Yhwh alone is to be worshipped (the actual existence of other gods is for most of the time left ambiguous; they may or may not be real, yes, but the Israelite is taught that he could not worship these foreign deities), on the popular level some syncretism existed - in part helped due to the huge similarities. For instance, it was also common back then to imagine the chief god having a female consort: while each nation’s chief god had a distinctive name, the mother goddess is invariably called Asherah or Ashtoreth or Astarte. Israel was no exception: at least some Israelites may have thought that Yhwh also had a consort named ‘Asherah’. Add to that the fact that the various nations used pretty much the same cult objects (altars, incense burners, vessels, etc.) in worship.
It wasn’t really too big a step to assume that oh, Yhwh, Qos, Moloch, etc. were really just different names for or manifestations of the same god: so when Israelites are spoken of as worshipping foreign gods like Moloch or ‘Ba’al’ they probably didn’t even think that they were worshipping an altogether different god from Yhwh; they would have thought that they are just adoring the same divinity under a different name/aspect. Which of course, for the prophets, wasn’t good enough: Yhwh and Yhwh alone is to be worshiped as Yhwh, and not under a foreign name/‘manifestation’.