Whey they're different
The usual set-theoretic construction of functions is as a relation between two sets $A$ and $B$, in which every $a \in A$ is related to exactly one $b \in B$ (but not necessarily a distinct one from any other $a' \in A$). To write it in formal symbols, $f: A \to B$ is logically equivalent to $\Bigl(f \subseteq A \times B \Bigr) \mathbin\& \Bigl( \forall a \in A \,\exists b \in B : \bigl[ (a,b) \in f \bigr] \mathbin\& \bigl[\forall b' \in B: (a,b') \in f \implies b' = b \bigr] \Bigr) .$ In particular, a function $f: \{ 1, 2 \} \to X \cup Y $ of the type described in your question is a two-element set $\{(1,x), (2,y)\}$ such that $x \in X$ and $y \in Y$. This is different from an element $(x,y) \in X \times Y$.
Why it doesn't matter that they're different
The reason why you should ignore the difference is because these are just two ways that you can reproduce the structure of an ordered pair in set theory. What matters is not how the ordered pairs (or any other particular structure) are built, but rather what you can do with them. For instance, the approach of category theory is to place the emphasis on the mappings of the projections $\pi_1$ and $\pi_2$ which give you the first and second entries of the tuples; and this reproduces everything you really care about for tuples, without fretting about "which set" the tuple is represented by.
Why I have a preference despite the fact that it doesn't matter that they're different
Nevertheless — I must confess a preference (purely aesthetic, mind you) for the definition in terms of functions, if you do choose to spend time contemplating definitions in terms of sets.
If you take the constructions very literally, $A \times B \times C \times D$ has to be interpreted as something like $A \times (B \times (C \times D))$, consisting of tuples $x = (a,(b,(c,d)))$, which is slightly ridiculous. I prefer to think of tuples as $x = (a,b,c,d) := \{(1,a), (2,b), (3,c), (4,d)\}$, which is usually what I really mean (because then $x_1 = a$, $x_2 = b$, etc. is no more than function evaluation).
Furthermore, an infinite product $A \times (B \times (C \times (\cdots))))$ would give rise to sets with infinitely decreasing chains of elementhood relations, which are ruled out by the usual axioms of set theory (specifically the Axiom of Foundation for ZFC or NBG). If you use functions $f: A \to \bigcup_{\alpha \in A} X_\alpha$ to define tuples, it really doesn't matter if $A$ happens to be an infinite set; the set of the tuples is still well-defined (although anyone who disbelieves in the Axiom of Choice may think that it could be empty even if none of the $X_\alpha$ are).
If you spend much time thinking about tuples in terms of sets, defining tuples as functions — and defining functions in terms of "arcs", a word which I choose almost-arbitrarily for the usual set $\{\{a\},\{a,b\}\}$ used to define ordered pairs — makes things a lot nicer.