Factorization of the trinomial $x^{2n}+Dx^n+1$? The following trinomials will factor for any $a$,
$$1+a(-3+a^2)x^3+x^6 = (1+ax+x^2)(1-ax-x^2+a^2x^2-ax^3+x^4)\tag{1}$$
and similarly for,
$$1+a(5-5a^2+a^4)x^5+x^{10}\tag{2}$$
$$1+a(-7+14a^2-7a^4+a^6)x^7+x^{14}\tag{3}$$
$$1+a(9-30a^2+27a^4-9a^6+a^8)x^9+x^{18}\tag{4}$$
and so on. (The second one is notable in that for general $a$ it has two factors, but if $a$ is an even-index Lucas number, then there is a third factor.) 
Questions:


*

*Given $P(x) = x^{2n}+Dx^n+1$ for all ODD $n>1$, is there a general formula for $D$ as a polynomial in $a$ such that $(1+ax+x^2)$ is a factor of $P(x)$?

*The fourth generally has 3 factors. Is there an odd $n$ such that $P(x)$ generally has four factors?


If we work in ${\mathbf Z}[x,a]/(x^2+ax+1)$, with $a$ and $x$ as independent indeterminates then we seek a polynomial $D_n$ in ${\mathbf Z}[a]$ such that $x^{2n}+D_nx^n+1 \equiv 0 \bmod x^2+ax+1$ for odd $n$.
Starting from $x^2 \equiv -ax-1 \bmod x^2+ax+1$ we can compute higher powers of $x$ to that modulus by using this relation for $x^2$, for instance $x^3 \equiv (a^2-1)x+a \bmod x^2+ax+1$ and $x^4 \equiv (-a^3+2a)x + (-a^2+1) \bmod x^2+ax+1$. In general, define polynomials $f_n(a)$ and $g_n(a)$ in ${\mathbf Z}[a]$ to fit 
$$
x^n \equiv f_n(a)x + g_n(a) \bmod x^2+ax+1.
$$
Then square both sides and use the reduction formula for $x^2 \bmod x^2+ax+1$ to get 
$$
x^{2n} \equiv (2f_n(a)g_n(a)-af_n(a)^2)x + (g_n(a)^2-f_n(a)^2) \bmod x^2+ax+1, 
$$
so for an unknown $D$ in ${\mathbf Z}[a]$, we have 
$$
x^{2n} + Dx^n + 1 \equiv (f_n(a)D - af_n(a)^2 + 2f_n(a)g_n(a))x + (g_n(a)^2-f_n(a)^2+ g_n(a)D+1).
$$
We want this to be $0 \bmod x^2+ax+1$, so we want to find $D$ satisfying the following two equations:
$$
f_n(a)D = af_n(a)^2 - 2f_n(a)g_n(a), \ \ \ g_n(a)D = f_n(a)^2 - g_n(a)^2 -1
$$
in ${\mathbf Z}[a]$. From the first equation, the obvious choice to make is 
$$
D = af_n(a) - 2g_n(a).
$$
Testing this with $n = 3, 5, 7, 9$ already recovers the coefficient of $x^n$ for these $n$ in your question, so we're clearly on the right track.
We also need to have this $D$ fit the second condition above, and that is the same as 
$$
g_n(a)(af_n(a)-2g_n(a)) \stackrel{?}{=} f_n(a)^2-g_n(a)^2+1,
$$
or equivalently 
$$
f_n(a)^2+g_n(a)^2 = af_n(a)g_n(a) - 1.
$$
I leave it as an exercise to check the coefficients of $x^n \bmod x^2+ax+1$ satisfy this constraint. 
Edit:  This calculation makes no distinction between even $n$ and odd $n$. It works for all $n$. For instance, when $n = 2$ and $n = 4$ the corresponding trinomials would be $x^4 + (-a^2+2)x^2 + 1$ and $x^6 + (a^3-3a)x^3 + 1$. Once I saw those I realized that in fact the coefficient of $x^n$ for all $n$ is a normalized $n$th Chebyshev polynomial up to a sign. Writing $a^n + 1/a^n = T_n(a + 1/a)$, we have $T_1(a) = a$, $T_2(a) = a^2 - 2$, $T_3(a) = a^3 - 3a$, $T_4(a) = a^4 - 4a^2 + 2$, and $T_5(a) = a^5 - 5a^3 + 5a$. Then your examples are simply $x^{2n}+(-1)^{n-1}T_n(a)x^n+1$.  So your task amounts to showing $x^{2n}+(-1)^{n-1}T_n(a)x^n+1 \equiv 0 \bmod x^2+ax+1$ for all $n \geq 1$.
In ${\mathbf Z}[a,x]/(x^2+ax+1)$, $x$ is a unit (with inverse ($-x-a$)) and $x + 1/x = -a$. In this ring \begin{eqnarray*}x^{2n} + (-1)^{n-1}T_n(a)x^n + 1 & = & x^n(x^n + 1/x^n + (-1)^{n-1}T_n(a)) \\ & = & x^n(T_n(x+1/x) + (-1)^{n-1}T_n(a)) \\ & = & x^n(T_n(-a) + (-1)^{n-1}T_n(a)).\end{eqnarray*}
Since $T_n(-a) = (-1)^nT_n(a)$, the sum $T_n(-a) + (-1)^{n-1}T_n(a)$ is 0, and that proves $x^{2n} + (-1)^{n-1}T_n(a)x^n + 1 \equiv 0 \bmod x^2 + ax + 1$ for all $n \geq 1$ (including even $n$).
