Maybe this isn't the best sub for this, but I was wanting the more unbiased historical context behind it because of how bizarre it is.
You may want to cross-post this to /r/academicbiblical. They’re the real experts on the biblical texts and the historical background behind them, and they do take it from an academic (not religiously faithful) viewpoint.
That said. The first part of Chapter 23 is focused on distinguishing the Israelites from their neighbors
So the fact that it opens with a ban on eunuchs isn’t too surprising. Using eunuchs in government and priestly roles was fairly common throughout the Middle East. It’s been viewed as a distinguishing mark between the Israelites and their neighbors. The Israelites were circumcised, the others allowed penile mutilation.
So the following verses put it into context. No eunuchs. No one from forbidden marriages. No Moabites or Ammonites, unless they’ve been Israelite for 10 generations. No Egyptians or Edomites unless they’ve been there for at least three generations. Castration in this context is apparently meant to link the eunuchs to these other groups of foreigners. And all of them are banned from the tabernacle.