Rolling a 1 or a 20 on an attack roll technically means that the result is going to hit or fail. However, that does not necessarily mean that the result is decided. There are skills out there (like Lucky himself!) That can modify the rolls, so there are even rare cases where your 1 or 20 can be modified after the roll but before the result is "determined". Then, until the full result of the attack is determined, he is allowed to use Lucky to roll it up again.
Jeremy Crawford confirm that this is the case of a natural 20 that should be exactly the same as a natural 1 for an attack roll:
Even a 20 is not immune to Lucky's dowry.
It is worth noting that for skill checks and safeguard rolls 1s and 20s have no special meaning and, therefore, would work with Lucky without any ambiguity. If you are playing with the variant in which skill tests and saving throws can have critical success or failure, then they will follow the above rules in the same way that attack rolls do by default.