As noted in the comment, this is Problem 3.54 in Testing Statistical Hypotheses (Third Edition) by E.L. Lehmann and Joseph P. Romano (this reference will be cited later in this answer for a few more times, so let me call it [TSH]). There is a hint provided after the exercise:
This follows from a consideration of the UMP tests for the one-sided hypotheses $H_1: \theta \geq \theta_1$ and $H_2: \theta \leq \theta_2$.
So let's develop this hint. To prepare for a rigorous proof, let's restate the problem formally as follows:
Let $\theta$ be a real number, and let $X$ have probability density (with respect to some measure $\mu$)
\begin{align*}
p_\theta(x) = C(\theta)e^{Q(\theta)T(x)}h(x),
\end{align*}
where $Q$ is strictly monotone. Given $\theta_1 < \theta_2$, prove there does not exist UMP test of size $\alpha$ (where $0 < \alpha < 1$) for testing
\begin{align*}
H: \theta \in [\theta_1, \theta_2] \text{ against } K: \theta \in (-\infty, \theta_1) \cup (\theta_2, +\infty). \tag{1}\label{1}
\end{align*}
Without loss of generality, assume $Q$ is increasing. Following the hint, let's consider the following two one-sided hypotheses:
\begin{align*}
& H_1: \theta \geq \theta_1 \text{ against } K_1: \theta < \theta_1. \tag{2}\label{2} \\
& H_2: \theta \leq \theta_2 \text{ against } K_2: \theta > \theta_2. \tag{3}\label{3}
\end{align*}
By Corollary 3.4.1 of [TSH], there exists size-$\alpha$ UMP tests (abbreviated as "UMP-$\alpha$" test hereafter) $\phi_1$ and $\phi_2$ for testing $\eqref{2}$ and $\eqref{3}$ respectively. Specifically,
\begin{align*}
& \phi_1(x) = \begin{cases}
1, & T(x) < C_1, \\
\gamma_1, & T(x) = C_1, \\
0, & T(x) > C_1.
\end{cases} \tag{4}\label{4} \\
& \phi_2(x) = \begin{cases}
1, & T(x) > C_2, \\
\gamma_2, & T(x) = C_2, \\
0, & T(x) < C_2.
\end{cases} \tag{5}\label{5}
\end{align*}
Here $C_i$ and $\gamma_i$ are determined by $E_{\theta_i}[\phi_i(X)] = \alpha$, $i = 1, 2$.
Now suppose there exists a UMP-$\alpha$ test $\phi$ for testing $\eqref{1}$, then it must also be$^\dagger$ a UMP-$\alpha$ test for testing $\eqref{2}$ and $\eqref{3}$. This implies that
\begin{align*}
& E_\theta[\phi(X)] = E_\theta[\phi_1(X)] \quad\text{ for all } \theta \leq \theta_1, \tag{6}\label{6} \\
& E_\theta[\phi(X)] = E_\theta[\phi_2(X)] \quad\text{ for all } \theta \geq \theta_2,
\tag{7}\label{7} \\
\end{align*}
Because $p_\theta$ is from a one-parameter exponential family, $\eqref{6}$ implies that$^\star$ that $\phi = \phi_1$ a.e. $\mu$, $\eqref{7}$ implies that $\phi = \phi_2$ a.e. $\mu$. Therefore $\phi_1 = \phi_2$ a.e. $\mu$. But this is impossible by inspecting expressions $\eqref{4}$ and $\eqref{5}$. We thus reached the contradiction and the proof is complete.
The non-existence of UMP-$\alpha$ test for testing the other two-sided hypotheses $H: \theta = \theta_0$ against $K: \theta \neq \theta_0$ can be proven analogously (hint: Consider ancillary one-sided hypotheses as $H_1: \theta = \theta_0 \text{ against } \theta > \theta_0$ and $H_2: \theta = \theta_0 \text{ against } \theta < \theta_0$).
As a recap, note that in the above proof, there are two places the "exponential family" condition are used: one place is deriving UMP tests $\eqref{4}$ and $\eqref{5}$, and the other place is concluding $\phi = \phi_1 = \phi_2$ a.e. $\mu$ from $\eqref{6}$ and $\eqref{7}$. That said, a UMP-$\alpha$ test may exist for testing $\eqref{1}$ for distribution families that are not exponential (e.g., see the second example in this post).
Technical Notes
1. Justification of $\dagger$
We need to show that if $\phi_1$ is a UMP-$\alpha$ test for testing $\eqref{1}$, then it must also be a UMP-$\alpha$ test for testing $\eqref{2}$ and $\eqref{3}$. This is just a matter of definition checking: $\phi$ is a UMP-$\alpha$ test for testing $\eqref{1}$ means that for any level-$\alpha$ test $\phi'$ for testing $\eqref{1}$, i.e., $\sup_{\theta \in [\theta_1, \theta_2]} E_\theta[\phi'(X)] \leq \alpha$, we have
\begin{align*}
E_\theta[\phi(X)] \geq E_\theta[\phi'(X)] \quad\text{ for all } \theta \in
(-\infty, \theta_1) \cup (\theta_2, +\infty). \tag{$\ast$}\label{star}
\end{align*}
Now for any level-$\alpha$ test $\tau$ for testing $\eqref{2}$, since $\sup_{\theta \geq \theta_1}E_\theta[\tau(X)] \leq \alpha$ implies that $\sup_{\theta \in [\theta_1, \theta_2]}E_\theta[\tau(X)] \leq \alpha$, $\tau$ is also a level-$\alpha$ test for testing $\eqref{1}$, it thus follows by $\eqref{star}$ that
\begin{align*}
E_\theta[\phi(X)] \geq E_\theta[\tau(X)] \quad\text{ for all } \theta \in
(-\infty, \theta_1) \cup (\theta_2, +\infty),
\end{align*}
which of course implies that
\begin{align*}
E_\theta[\phi(X)] \geq E_\theta[\tau(X)] \quad\text{ for all } \theta < \theta_1,
\end{align*}
this is exactly the meaning of $\phi$ is a UMP-$\alpha$ test for testing $\eqref{2}$. That $\phi$ is also a UMP-$\alpha$ test for testing $\eqref{3}$ can be proven similarly.
2. Justification of $\star$
This is very similar to the proof of the completeness of the family of $T(X)$ in $p_\theta$ as $\theta$ ranges over a set containing an interior point (thus the proof is not that easy!). As a sketch of the proof, first reformulate $\eqref{6}$ as $E_\theta[f(X)] = 0$ for all $\theta \leq \theta_1$, where $f = \phi - \phi_1$. The goal is to deduce $f = 0$ a.e. $\mu$ from this condition. One can then follow the proof of Theorem 4.3.1 of [TSH] in an almost word-for-word manner to arrive at the goal.