Requiring that $f$ be continuous on each element of the partition does not suffice - for example, consider the partition $\mathbb{R}=(-\infty,0]\cup (0,\infty)$ and the function $f:\mathbb{R}\to\mathbb{R}$ defined by $f(x)=\begin{cases}0\text{ if }x\leq 0\\ 1\text{ if }x>0\end{cases}$ which is continuous on each element of the partition, but not continuous overall.
Nor does requiring that $f$ be continuous on the closure of each element of the partition suffice - for example, $\mathbb{R}=\bigcup_{a\in\mathbb{R}}P_a$ where $P_a=\{a\}$ is a partition of $\mathbb{R}$, and for every $a\in\mathbb{R}$, $P_a=\overline{P_a}$. Any function $\mathbb{R}\to Y$ is continuous on each $P_a$, but there are many discontinuous functions with $\mathbb{R}$ as domain.
However, it is true that if $X=\bigcup_{\alpha\in A}P_\alpha$ is an open cover of $X$, i.e. each $P_\alpha$ is an open subset of $X$, then $f:X\to Y$ is continuous if and only if each restriction $f|_{P_\alpha}:P_\alpha\to Y$ is continuous. This is easy to see: suppose that $U\subseteq Y$ is an open subset. If each $f|_{P_\alpha}$ is continuous, then $f|_{P_\alpha}^{-1}(U)=\{x\in P_\alpha\mid f(x)\in U\}=f^{-1}(U)\cap P_\alpha$ is open in $P_\alpha$ (which has the subspace topology from $X$). Because each $P_\alpha$ is open in $X$, a subset of $P_\alpha$ is open in the subspace topology if and only if it is open as a subset of $X$. Thus, each $f|_{P_\alpha}^{-1}(U)$ is open as a subset of $X$, and hence $f^{-1}(U)=f^{-1}(U)\cap X= f^{-1}(U)\cap\left(\bigcup_{\alpha\in A} P_\alpha \right)= \bigcup_{\alpha\in A}f|_{P_\alpha}^{-1}(U)$ is an open subset of $X$. Thus, $f$ is continuous.
However, it is often the case that an open cover cannot also be a partition. A space is called connected when the only open cover that is also a partition is the trivial open cover, i.e. $\{X\}$. Intuitively, connected means exactly what you'd think - there aren't two "separate pieces". For example, $\mathbb{R}^n$, $\mathbb{S}^n$, and $\mathbb{T}^n$ are all connected, while $(0,1)\cup (2,3)$ is disconnected.