To this discussion I would add that it is possible the passage in Deuteronomy is only a restriction on serving in positions of authority, not exclusions from the Temple or community.
The Tanakh translates בִּקְהַ֖ל יְהוָֽה in Deuteronomy 23 as "congregation of the LORD." Bernard M. Levinson's commentary in the JPS Study Bible states:
The congregation of the LORD (v.2) served as the national governing body, akin to to a popular legislature, that was charged with a broad range of judicial, political, and policy matters (Judges 20:2) 1
The verse in Judges which Levinson cites:
And the chiefs of all the people, of all the tribes of Israel, presented themselves in the assembly of the people of God, 400,000 men on foot that drew the sword. (20:2 ESV)
Additional support for understanding Deuteronomy in the context of restrictions on serving in positions of authority can be seen in Micah:
Woe to those who devise wickedness
and work evil on their beds!
When the morning dawns, they perform it,
because it is in the power of their hand.
They covet fields and seize them,
and houses, and take them away;
they oppress a man and his house,
a man and his inheritance.
Therefore thus says the LORD:
behold, against this family I am devising disaster,
from which you cannot remove your necks,
and you shall not walk haughtily,
for it will be a time of disaster. In that day they shall take up a taunt song against you
and moan bitterly,
and say, “We are utterly ruined;
he changes the portion of my people;
how he removes it from me!
To an apostate he allots our fields.” (2:1-4 ESV)
Therefore you will have none to cast the line by lot
in the assembly of the LORD. (2:5 ESV)
The phrase "assembly of the LORD" in Micah is בִּקְהַ֖ל יְהוָֽה as in Deuteronomy 23.
Ehud Ben Zvi states Micah 2:1-5 is on social ethics, divine judgement and hope, noting:
Elite people within society design (or, "work") evil; the LORD plans (Heb) "evil" (misfortune) against them. Moreover, members of this group are able to do so because they have the power; the LORD certainly has the power to carry "evil" (misfortune), and God's might is infinitely superior to these people (cf. Prov 22.23) 2
The JPS Tanakh translation of verse 5 notes the phrase is speaking to legal or judicial matters:
Truly, none of you shall cast a lot cordd in the assembly of the LORD! (2:5 JPS)
Note d - On apiece of land, thus acquiring title to it; cf. Josh 18.6 and Ps 16.6
Ehud Ben Zvi notes verse 5 appears to apply to future generations:
The descendants of the transgressors will not be part of the assembly of the LORD. This verse suggests a transgenerational aspect in the divine punishment. 3
Thus, while lacking a specific number of generations, Micah otherwise appears to be in agreement with Deuteronomy 23.
In addition to "God knows what is best" I think there is good reason to establish a generational "waiting period" before allowing certain groups to be placed in decision making roles which can impact the nation.
1. Bernard M. Levinson, The Jewish Study Bible, Oxford University Press, 2004, p. 418
2. Ehud Ben Zvi, The Jewish Study Bible, Oxford University Press, 2004, p. 1208