You mentioned this practice in relation to the US; the legal basis at least would be section 2 of the 14th amendment:
Representatives shall be apportioned among the several states according to their respective numbers, counting the whole number of persons in each state, excluding Indians not taxed. But when the right to vote at any election for the choice of electors for President and Vice President of the United States, Representatives in Congress, the executive and judicial officers of a state, or the members of the legislature thereof, is denied to any of the male inhabitants of such state, being twenty-one years of age, and citizens of the United States, or in any way abridged, except for participation in rebellion, or other crime, the basis of representation therein shall be reduced in the proportion which the number of such male citizens shall bear to the whole number of male citizens twenty-one years of age in such state.
Felony disenfranchisement was specifically upheld because of this in the case Richardson v. Ramirez.
The legal basis of the practice in the US is sort of an anachronism since a major reason the amendment is worded that way was to help maintain Republican power and suppress the Democrats who were previously part of the Confederacy. So the historical case that actively grants the state this power, came about because the Republicans wanted to more easily maintained political power. This seems like an obvious avenue for them to take since the power to curtail (and expand) voting rights is pretty powerful in a democracy. It granted a legal basis to Republican rule beyond just military occupation of the South.
It's hard to judge the intent of the practice in all individual cases since laws regarding felony disenfranchisement were passed before and after the 14th amendment and the Reconstruction era. But given the history of Jim Crow and poll taxes, literacy tests, and grandfather clauses meant to restrict voting rights, this practice seems like another obvious way to control voting rights and maintain white supremacy. Sometimes its really obvious, like the 1901 Alabama state constitution that removes voting rights for among other things, "miscegenation", which of course, is itself a crime. Other times we have to look at the results to give us clues about what the intent may have been. For example, when we examine the relative rates of current felony disenfranchisement and where it occurs, the desire to maintain political power and white supremacy via control of voting rights is probably still present:
