Why can't a set have two elements of the same value? Suppose I have two sets, $A$ and $B$:
$$A = \{1, 2, 3, 4, 5\} \\ B = \{1, 1, 2, 3, 4\}$$
Set $A$ is valid, but set $B$ isn't because not all of its elements are unique. My question is, why can't sets contain duplicate elements?

Short Answer:
The axioms of the Set Theory do not allow us to distinguish between two sets like $A = \{1,2\}$ and $B = \{1,1,2\}$. And every sentence valid about sets should be derived in some way from the axioms.
Explained:
The logic of the set theory is extensional, that means that doesn't matter the nature of a set, just its extension. The set $A = \{1,1,2,3,4\}$ could be considered different from $B = \{1,2,3,4\}$ in intension, but they are not different in extension, since $1 = 1$, both sets have the same elements. Even if one instance of the number $1$ precedes the other, the axioms of the set theory do not allow to distinguish between two sets using the order of its elements, because the notion of order is not defined by the axioms of the theory. To do that, the ordered pair is defined as follows: $$\left(a,b\right) \equiv \{\{a\},\{a,b\}\}$$ Thus $\left(a,b\right) \neq \left(b,a\right)$ since  $\{\{a\},\{a,b\}\} \neq \{\{b\},\{b,a\}\}$. Thus, the set $A$ can't be distinguished fom B using its order. Moreover, the cardinality of two sets is never used to prove that two sets are different.
What about the ordered pair $\left(1,1\right) \equiv \{\{1\},\{1,1\}\} $? Since $1 = 1$ we have $\{1,1\} \equiv \{1\}$, this pair is a well known structure called singlenton, obtained as a consequence of the axiom of pairing and (as you can see) the axiom of extension. Moreover, since $\{1\}$ is present in $\left(1,1\right)$ two times, $\left(1,1\right) \equiv \{\{1\}\}$ another singlenton. Which is not a problem for the Analysis in $\mathbb{R}^2$, because this pair is different from $\{1\}$, a subset of  $\mathbb{R}$, and different from each other pair in $\mathbb{R}^2$. The moral of this story is that you can't distinguish between the first and the second element of $\left(1,1\right)$, and it's ok.
Although the symbol "$\equiv$" is used to introduce syntactic abbreviations instead of  semantic equality denoted by "$=$", this difference is just important in the study of Formal Languages, but not really important for this case, since the axiom of extension is what allows us to consider $\{1,1\} \equiv \{1\}$ as $\{1,1\} = \{1\}$. Just read the Section 3 of the book Naive Set Theory of Paul R. Halmos, what introduces the term singlenton in that way, and that's how is used by the specialized literature.
Other reference to understand the difference between intension and extension.
https://plato.stanford.edu/entries/logic-intensional/
