For each integer $k$ write $k:S^2\rightarrow S^2$ for the degree $k$ self-map. Then, since $4\simeq 2\circ 2$ we have a homotopy commutative diagram
$\require{AMScd}$
\begin{CD}
S^2@>4>> S^2@>p>>Y\\
@V2 V V @VVid_{S^2} V@VV \theta V\\
S^2 @>2>> S^2@>q>>X
\end{CD}
where each row is the cofiber sequence that defines the spaces $X$, $Y$, and $\theta:Y\rightarrow X$ is the induced map of cofibers. The map $\theta$ is clearly what you are looking for.
Let's do this in a bit more detail. First observe that $X$, $Y$ are the topological pushouts in the diagrams
$\require{AMScd}$
\begin{CD}
S^2@>4>> S^2\\
@Vi V V @VVpV\\
D^3 @>l>> Y
\end{CD}$\require{AMScd}$
\begin{CD}
S^2@>2>> S^2\\
@Vj V V @VVqV\\
D^3 @>k>> X
\end{CD}
where $i=j$ are the boundary inclusions (they are the same map, but we'll assign them different symbols to make clear to which we are referring).
First we note that since the composite $j\circ2:S^2\rightarrow S^2\rightarrow D^3$ is null-homotopic and $i$ is a cofibration, there exists and extension $\underline 2:D^3\rightarrow D^3$ such that $\underline 2\circ i=j\circ 2$. This then gives us a map $k\circ\underline 2:D^3\rightarrow X$ that satisfies
$$(k\circ\underline 2)\circ i=k\circ(\underline 2\circ i)=k\circ (j\circ 2)=(k\circ j)\circ 2=(q\circ 2)\circ 2=q\circ (2\circ 2).$$
Now choose a homotopy $F:2\circ 2\simeq 4$ so that $q\circ (2\circ2)\simeq q\circ 4$. Using again the fact that $i$ is a cofibration we get a homotopy $G:D^3\times I\rightarrow X$ starting at $G_0=k\circ \underline 2$ and satisfying $G_t\circ i= q\circ F_t$ for each $t\in I$. In particular its end map $G_1:D^3\rightarrow X$ now satisfies
$$G_1\circ i= q\circ F_1=q\circ 4.$$
It follows using the that $Y$ is the pushout of the maps $i$ and $4$ that there is an induced map $\theta:Y\rightarrow X$ satisfying
$$\theta\circ p=q\circ id_{S^2},\qquad \theta\circ l=G_1\simeq k\circ \underline 2$$
and the first of these properties is exactly what you are looking for.
It may help you to visualise things if you put the pushout square for $Y$ above the pushout square for $X$ and draw in all the maps we've used.
Finally note that although the identity map of $S^2$ does not extent to a map $X\rightarrow Y$, the degree $2$ map does. You may like to follow the steps we gone through here to write down the map it induces.