Estimating $\sum_{n\leq x: n \in A} d(n)^a$ from below for large sets $A\subset \{1,2,\ldots,x\}.$

Even if you take $Z(x)=(1-\varepsilon)x$ for some fixed $0<\varepsilon<1$, you are going to get

$$ M=x(\ln x)^{a\ln 2+o(1)}. $$

To prove this, observe that both $\omega(n)$ and $\Omega(n)$ have normal order $\ln\ln n$ (here $\Omega$ and $\omega$ are numbers of prime factors with and without multiplicity respectively). Also note that

$$ 2^{\omega(n)}\leq d(n)\leq 2^{\Omega(n)} $$

for every $n$, which implies that for any $\delta>0$ for all but $o(x)$ numbers $n\leq x$ we have

$$ (\ln x)^{\ln 2-\delta}\leq d(n) \leq (\ln x)^{\ln 2+\delta}. $$

Therefore, for any $A\subset [1,x]\cap \mathbb N$ with $|A|\geq cx$ for some $c>0$ we have

$$ S_a^A\geq (|A|-o(x))(\ln x)^{a(\ln 2-\delta)}, $$

so that $M\gg x(\ln x)^{a(\ln 2-\delta)}$. On the other hand, if you throw all the $n$ with $n>(\ln x)^{\ln 2+\delta}$ out of your interval, you will still have $x-o(x)$ numbers left. This implies that for any $\varepsilon>0$ and $x$ large enough there is $A$ with $|A|\geq (1-\varepsilon)x$ such that

$$ S_a^A\leq |A|(\ln x)^{a(\ln 2+\delta)}. $$