This is hard to answer. Why are there 20 amino acids in proteins, someone might ask? Which came first? DNA, proteins, or was it RNA? Origins of life research tries to answer these questions, but I am not an expert of that field.
As for why are there 20 encoded amino acids (+ selenocysteine and pyrrolysine)?
I've read that codon similarities hint at an original more compact alphabet of two base codons (allowing for up to 15 distinct amino acids and a stop).
I've also read that the "more recent" amino acids, like cysteine, are more readily oxidized and thus provided some advantage as atmospheric oxygen levels increased.
But all of these are guesses about the world before LUCA, which is really lost to us.