In Deuteronomy 23, certain people are excluded from the "congregation of YHWH", but the meaning is uncertain. Does it refer to the Temple, government, voting, etc.? I don't think it means being excluded from the nation completely. That doesn't align with God's character or the prophets. If that's what it meant, it would probably say "cut off from the people" or something like that. Rather than total exclusion from #israel, being excluded from the congregation of YHWH means being excluded from certain formal aspects of community life.
For example, inheritance of the covenant and land are central to Israelite identity. A eunuch (v1) has no heirs and so can never fully participate in that aspect of the community. He's a fruitless tree, a "dry twig". "Bastard" in v2 isn't about unwed parents. It's about the child of a forbidden union. He inherits neither covenant nor land. If he is faithful to Adonai, he is grafted into the nation like a former gentile.