Any clause in a law which makes an exception for people or things if, when the law was passed, they were already doing whatever is being forbidden. And related concepts. Building codes often grant exceptions for buildings built before the code was enacted, for example.

The phrase comes from a series of similar changes in the constitutions of six southern US states between 1895 and 1910. The right to vote was limited to literate people with some arbitrary amount of wealth, but exceptions were made for people who'd had the right to vote during the Civil War, or whose ancestors had had that right at the time. By chance, quite coincidentally, the set of people allowed to vote in those states during the Civil War was the set of all white people in those states, and both poverty and illiteracy were depressingly common among black and white people both. The effect, perhaps unintentional, was to limit the franchise to most whites (not counting poor, illiterate immigrants) and a minority of blacks.

The United States Supreme Court took one look at this in 1915, rolled its collective eye, and told them to go home and let everybody vote. Other equally unfortunate coincidences followed, and things didn't really get set right until the 1960s. I've read that there are counties in the South to this day where some odd arrangements are in place, but it does seem that coincidences are a lot less common than they once were.

Note that nobody, North or South, let chicks vote at all back then, before we of the harsh vowels up here start patting ourselves on the back too much.