[proofplan]
The proof is pointwise. Throughout, $\gcd(a,P(z))$ denotes the positive greatest common divisor of the integers $a$ and $P(z)$. For each $a \in A$, we compare the indicator of the event $\gcd(a,P(z)) = 1$ with the quadratic Selberg expression attached to $a$. If $a$ survives the sieve, the only divisor of $\gcd(a,P(z))$ is $1$, so the inner sum is $\lambda_1 = 1$. If $a$ does not survive, the square is still non-negative because the Selberg weights are real-valued; the level $D$ condition is used only through the definition of Selberg weight, in particular the normalization and real-valuedness needed here. Summing the resulting pointwise inequality over the finite set $A$ gives the claimed majorization.
[/proofplan]
[step:Define the pointwise Selberg quadratic expression]
Define the map
\begin{align*}
Q: A \to [0,\infty)
\end{align*}
by declaring, for each $a \in A$,
\begin{align*}
Q(a) := \left(\sum_{d \mid \gcd(a,P(z))} \lambda_d\right)^2.
\end{align*}
The divisor sum is finite because $\gcd(a,P(z))$ is a positive integer. Since $(\lambda_d)$ is a Selberg weight of level $D$, the weights are real-valued and satisfy the normalization $\lambda_1=1$; the support restriction coming from the level is not otherwise needed for this pointwise majorization. Hence the displayed square is non-negative, so $Q(a) \in [0,\infty)$ for every $a \in A$.
[/step]
[step:Compare the sifted indicator with the quadratic expression pointwise]
Define the indicator map
\begin{align*}
\mathbb{1}_{\mathrm{sift}}: A \to \{0,1\}.
\end{align*}
For $a \in A$, set $\mathbb{1}_{\mathrm{sift}}(a)=1$ when $\gcd(a,P(z))=1$, and set $\mathbb{1}_{\mathrm{sift}}(a)=0$ when $\gcd(a,P(z))>1$.
We prove that
\begin{align*}
\mathbb{1}_{\mathrm{sift}}(a) \leq Q(a)
\end{align*}
for every $a \in A$.
If $\gcd(a,P(z)) = 1$, then the only positive divisor of $\gcd(a,P(z))$ is $1$. Hence
\begin{align*}
\sum_{d \mid \gcd(a,P(z))} \lambda_d = \lambda_1 = 1,
\end{align*}
and therefore $Q(a)=1=\mathbb{1}_{\mathrm{sift}}(a)$.
If $\gcd(a,P(z)) > 1$, then $\mathbb{1}_{\mathrm{sift}}(a)=0$, while $Q(a) \geq 0$ by the previous step. Thus $\mathbb{1}_{\mathrm{sift}}(a) \leq Q(a)$ in this case as well.
[guided]
The purpose of the Selberg weight is to create a non-negative expression that is at least $1$ on every element surviving the sieve. For each $a \in A$, define
\begin{align*}
Q(a) := \left(\sum_{d \mid \gcd(a,P(z))} \lambda_d\right)^2.
\end{align*}
This is a real square because the weights $\lambda_d$ are real. Therefore $Q(a) \geq 0$ for every $a \in A$.
Now define the map
\begin{align*}
\mathbb{1}_{\mathrm{sift}}: A \to \{0,1\}.
\end{align*}
For $a \in A$, set $\mathbb{1}_{\mathrm{sift}}(a)=1$ when $\gcd(a,P(z))=1$, and set $\mathbb{1}_{\mathrm{sift}}(a)=0$ when $\gcd(a,P(z))>1$.
This indicator records exactly whether $a$ is counted by $S(A,P,z)$.
We compare $\mathbb{1}_{\mathrm{sift}}(a)$ and $Q(a)$ by cases. Suppose first that $\gcd(a,P(z)) = 1$. Then the positive divisors of $\gcd(a,P(z))$ consist only of $1$, so the inner divisor sum reduces to
\begin{align*}
\sum_{d \mid \gcd(a,P(z))} \lambda_d = \lambda_1.
\end{align*}
Because $(\lambda_d)$ is a Selberg weight, $\lambda_1=1$. Hence
\begin{align*}
Q(a)=\left(\lambda_1\right)^2=1.
\end{align*}
Since $\mathbb{1}_{\mathrm{sift}}(a)=1$ in this case, we get $\mathbb{1}_{\mathrm{sift}}(a)=Q(a)$.
Suppose instead that $\gcd(a,P(z)) > 1$. Then $a$ is not counted by the sifted set, so $\mathbb{1}_{\mathrm{sift}}(a)=0$. The quadratic expression satisfies $Q(a)\geq 0$, because it is the square of a real number. Therefore
\begin{align*}
\mathbb{1}_{\mathrm{sift}}(a) = 0 \leq Q(a).
\end{align*}
In both cases,
\begin{align*}
\mathbb{1}_{\mathrm{sift}}(a) \leq Q(a).
\end{align*}
[/guided]
[/step]
[step:Sum the pointwise inequality over the finite set]
Because $A$ is finite, we may sum the pointwise inequality over all $a \in A$:
\begin{align*}
\sum_{a \in A} \mathbb{1}_{\mathrm{sift}}(a) \leq \sum_{a \in A} Q(a).
\end{align*}
By the definition of $\mathbb{1}_{\mathrm{sift}}$ and the definition
\begin{align*}
S(A,P,z) := \#\{a \in A : \gcd(a,P(z)) = 1\},
\end{align*}
the left-hand side is exactly
\begin{align*}
\sum_{a \in A} \mathbb{1}_{\mathrm{sift}}(a) = \#\{a \in A : \gcd(a,P(z)) = 1\} = S(A,P,z).
\end{align*}
Substituting the definition of $Q(a)$ on the right-hand side gives
\begin{align*}
S(A,P,z) \leq \sum_{a \in A}\left(\sum_{d \mid \gcd(a,P(z))} \lambda_d\right)^2.
\end{align*}
This is the desired Selberg quadratic majorant.
[/step]