I would like to supply another answer to this interesting question. I learnt the following example in a masters thesis of Cecil Eugene Denney (Kansas State University, 1966). Here is a link to the thesis. What follows below is a modified version of Example 3 in page 27 of the thesis.

**Example.** Let $X=\{a, b\}$ be a topological space whose only open sets are $\emptyset$ and $X$ itself (so $X$ has the indiscrete topology). Let $Y=\mathbb{R}$ be the set of all real numbers with the standard topology. We will consider the topological space $X\times Y$. Consider the following two subsets of $X\times Y$:
$$
C = \{(a, y): 1\leq y < 3\} \cup \{(b, y): 3\leq y \leq 4\}
$$
and
$$
D = \{(a, y): 2<y \leq 4\} \cup \{(b, y): 1\leq y \leq 2\}.
$$
We claim that $C$ and $D$ are both compact. Indeed, in given any open cover $\mathcal{U}$ for $C$, each open set must be of the form $X\times U$ where $U$ is an open subset of $Y$ (this is where we use the fact that the only open subsets of $X$ are $\emptyset$ and $X$). Using the projection $\pi_Y: X\times Y \to Y$, we note that the collection of all $U$ such that $X\times U\in\mathcal{U}$ forms an open cover of $\pi_Y(C) = [1, 4]$ which is compact. Thus, there are finitely many $U_i$ which cover $[1, 4]$, and consequently finitely many $X\times U_i$ which cover $C$. This shows $C$ is compact, and the verification for compactness of $D$ is identical.

However, $C\cap D = \{(a, y): 2 < y < 3\}$ is homeomorphic, via the projection $\pi_Y$, to the open interval $(2, 3)$ in $Y=\mathbb{R}$, and it is well-known that $(2, 3)$ is **not** compact.