Where is the flaw in my proof that the union of two continuous functions is continuous?

As is often the problem in mathematical proofs, there's an issue immediately after you write "clearly"; you only know that $(h(y_n))_{n\geq0} = (f(y_n))_{n\geq0}$, and we don't necessarily know what $(f(y_n))_{n\geq0}$ converges to (if at all!). By saying $h(y_n) \to h(c)$, you implicitly said that $f(y_n) \to f(c)$ but what if $c \in B$ (or neither $A$ nor $B$)?


Take $A = [-1, 0)$ and $B = [0, 1]$ and take $f(x) = -1$ and $g(x) = 1$, then your function $h$ is not continuous at $0$. Taking $x_n = -1/n$, $x_n \to 0$, but $h(x_n) \to -1 \neq h(0)$.

Your conjecture could be repaired in various ways. E.g., it is true if $A$ and $B$ are required to have disjoint closures. However, your line of proof would have to be that because $A$ and $B$ have disjoint closures, if $x_n$ is sequence in $A \cup B$ that converges to a point $x \in A$ (resp. $B$), then for all large enough $n$, $x_n \in A$ (resp. $x_n \in B$). I.e., one of your subsequences $y_n$ and $z_n$ would be finite.

The condition that $A$ and $B$ have disjoint closures, i.e., that $\overline{A}\cap\overline{B} = \emptyset$, can be relaxed to $A \cap \overline{B} = \overline{A} \cap B = \emptyset$. This weaker condition is necessary as well as sufficient: if either $A \cap \overline{B}$ or $\overline{A} \cap B$ is non-empty, then with $f$ and $g$ constant functions with different values, you get a counterexample.