Your question is related to Wahba's problem, which initially is defined for rotation matrices but can also be defined for unit quaternions and can be solved with Davenport's q-method. However, in order to have a uniquely defined rotation it is required to have at least two pairs of vectors.
You only have one pair of vectors. The second pair could be chosen as the rotation axis, which should remain unchanged during the rotation. For this rotation axis you can choose any unit vector which is equidistant to both vectors of the first pair. When denoting the vector/imaginary parts normalized to unit length of $X$ and $Y$ as $x$ and $y$ respectively then the rotation axis $r$ can be parameterized using
$$
\begin{align}
n &= \frac{x \times y}{\|x \times y\|}, \\
m &= \frac{x + y}{\|x + y\|}, \\
r &= \cos(\phi)\,n + \sin(\phi)\,m.
\end{align}
$$
The smallest and largest resulting rotation (in terms of rotation angle) are obtained using $\phi=0$ and $\phi=\pi/2$ respectively, with $n$ and $m$ as axis of rotation respectively. The corresponding unit quaternions are
$$
q = \begin{bmatrix} m\cdot x \\ \|x \times m\|\,n\end{bmatrix}, \quad
q = \begin{bmatrix} 0 \\ m\end{bmatrix},
$$
respectively. It can be noted that this method will fail if $x$ and $y$ are linear dependent (i.e. $y = \pm x$). When $y = x$ then any rotation with $x$ as rotation axis would suffice, so $q = \begin{bmatrix}\cos(\theta) & \sin(\theta)\,x^\top\end{bmatrix}^\top$. When $y = -x$ then any rotation of $\pi$ radians around any axis $t$, which is perpendicular to $x$, would suffice, so $q = \begin{bmatrix}0 & t^\top\end{bmatrix}^\top$.