If that seems strange to us, it's because our culture is infused at the roots with a Biblical worldview, whether or not we recognize it. The Old Testament Law given to the Israelites forbid them from incorporating any kind of sexual component in their public worship. Israelite (later Jewish) sexual ethics as embodied in the Hebrew scriptures were upheld by Christians, who carried them out into the Western world. Eventually, when Christianity came to dominate the religious landscape of the West, a Christian sex ethic also became the cultural norm -- an ethic in which sex is completely unrelated to public worship.
But in the ancient Near East, the Israelites were actually unique in this respect. It was ordinary for the people of Canaan and surrounding cultures to include sexual acts as "legitimate" forms of worship to their gods. There's a reason Deuteronomy 23:17 notes that no Israelite man or woman was permitted to become a "shrine prostitute." All the peoples around them supported and engaged in shrine prostitution.
I mean, even the phrase "shrine prostitution" is bizarre to us. Bizarre and offensive -- if you really want to feel the impact of it, try editing it for a modern context and make it "church prostitute." Imagine that being an official job title, a paid position, for any modern congregation. Senior pastor; youth pastor; administrative assistant; janitor; prostitute. Squick. That is a seriously offensive idea in my culture.
In the ancient Near East? Not offensive. Common. Legitimized as something "sacred," something that honored the gods, especially fertility gods.
Knowing that the sexual immorality talked about in Numbers 25:1 was probably part of the same festival described in 25:2, we can perhaps reconstruct the situation thus:
The Israelites are moving north after their 40-year exile in the wilderness. They expect (and receive) hostility from the people who live in the areas they move through; the book of Numbers describes a lot of the early examples of that hostility.
This one time, though, something different happens. Instead of spears in the face, the Israelites get invited to a festival. The local people want to be nice to them for a change.
Festivals are fun. Full of fun stuff, like eating and drinking and sex (even though Yahweh God doesn't like that, all the other gods do).
Maybe it would be diplomatic to accept the invitation? Because if the Israelites refuse, maybe they will offend their hosts. Maybe they'll go back to spears in the face. But if they accept, maybe the local people will keep being nice to them. Maybe they'll let the Israelites move on through peacefully, which is all they were trying to do in the first place.
Plus, parties are fun. There will be lots of meat from the sacrifices. Some of those Moabite women are really pretty too.
And just like that, some of the Israelites convince themselves that breaking their sworn agreement to only worship the LORD as well as indulging in adulterous (and otherwise off-limits) sex is a fine idea. Maybe just this once. To make nice with the neighbors.
That's a different picture of what's going on than I get to by using a modern set of assumptions, not taking into account the idea that feasting and sex were connected with worship in the ancient world. Granted, in this case the outcome doesn't seem hugely different. Under both interpretations the Israelites are engaging in the same forbidden actions. But there are cases where it makes a much bigger difference -- where, without understanding the culture of the ancient world, we misunderstand what scripture is trying to tell us completely, or we just don't know what to make of it at all.
To understand the Bible as well as we can, understanding cultural background is vital. That's why I'm pursuing a Master's degree in biblical studies, to learn this kind of information. I want the background to understand and interpret scripture well, and I want to write about it and help other people understand better too.