How are codes like 5421 and 2421 unique?
Codes like 5421 and 2421 are not unique, and this is one of their advantages. For example, 2421 is self-complementing: computing the 9-complement of a digit is the same as negating its bits. In textbooks you can find tables in which the authors choose one possible code for each digit, but this choice is arbitrary, and you might find different choices in different textbooks.

Let me also mention that BCD has been gradually losing favor, and I expect only old hardware to use anything other than 8421 (if at all). Most of the interest in BCD is historical, since modern architectures don't use BCD. I suspect that material about BCD is there mostly because of inertia, though BCD might still be used in conservative industries such as banking.