For a counterexample, you can consider a connected version of the Tychonoff plank. That is, let $X=[0,1]\times L$ where $L$ is the closed long line (with right endpoint $\omega_1$). Let $Y=[0,1)\times\{\omega_1\}\cup\{1\}\times (L\setminus\{\omega_1\})$. Then $Y$ is disconnected, since $[0,1)\times\{\omega_1\}$ and $\{1\}\times (L\setminus\{\omega_1\})$ are clopen in $Y$. However, $[0,1)\times\{\omega_1\}$ and $\{1\}\times (L\setminus\{\omega_1\})$ cannot be separated by open sets in $X$ (since any neighborhood of $[0,1)\times\{\omega_1\}$ must contain an entire rectangle $[0,1)\times (a,\omega_1]$ for some $a<\omega_1$) and so $Y$ cannot be covered by disjoint open subsets of $X$ that have nonempty intersection with $Y$.
More generally, a slight strengthening of the property you ask for is equivalent to complete normality. (So, counterexamples to a slight strengthening of your question are just compact Hausdorff spaces that are not completely normal, or equivalently completely regular spaces that are not normal.) To be precise, the following are equivalent for any topological space $X$:
- $X$ is completely normal, i.e. every subspace of $X$ is normal. (Here I use "normal" to mean disjoint closed sets have disjoint neighborhoods, without requiring points to be closed.)
- If $Y\subseteq X$ and $Y=A\cup B$ is a partition of $Y$ into sets that are clopen in $Y$, then there exist disjoint open $U,V\subseteq X$ such that $A=U\cap Y$ and $B=V\cap Y$.
First, suppose $X$ is completely normal, $Y\subseteq X$, and $A,B\subseteq Y$ is a partition of $Y$ into two subsets that are clopen in $Y$. Let $C=\overline{A}\cap\overline{B}$ (where the closures are taken in $X$) and $Z=X\setminus C$. Then $\overline{A}\cap Z$ and $\overline{B}\cap Z$ are disjoint closed subsets of $Z$. Since $Z$ is normal, they can be separated by open subsets $U,V\subseteq Z$. But $Z$ is open in $X$, so $U$ and $V$ are also open in $X$, and satisfy $U\cap Y=A$ and $V\cap Y=B$.
Conversely, suppose $X$ satisfies (2), $Z\subseteq X$, and $A,B\subseteq Z$ are disjoint and closed in $Z$. Then $A$ and $B$ are both clopen in $Y=A\cup B$, so by (2) they can be separated by open subsets of $X$, and hence also by open subsets of $Z$. This shows that any $Z\subseteq X$ is normal.