False duality of diagonalizable/constant group scheme? The following is an introduction to constant group scheme and diagonalizable group scheme.

Let $M$ be an arbitrary abstract group and $S$ be a scheme. Let $M_S=\coprod_{i\in M}S_i$ where $S_i=S$,which can be constructed via glueing data of a scheme see tag 01JA. Then $M_S$ is called the constant group scheme over $S$ associated to $M$. And for any $S$-scheme $T$, $M_S(T)=\{\text{locally constant functions }f:|T|\to M\}$, where $|T|$ has Zariski topology and $M$ has discrete topology, and locally constant function is defined to be $\forall t\in T,\exists U\ni t\text{ open}$ s.t. $f(U)={f(t)}$. see tag 03YW
The dual of a group scheme $G$ over $S$ is a scheme representing the functor $T/S\mapsto \mathrm{Hom}_{\mathrm{Gr}-T}(G_T,\mathbb{G}_m)$. For a constant group scheme $M_S$, its dual is denoted as $D(M)$ or $D_S(M)$ and they are precisely the diagonalizable group schemes. In particular, it exists and $\DeclareMathOperator{\Spec}{Spec}D_S(M)\cong \Spec \mathbb{Z}[M]\times_{\Spec \mathbb{Z}}S$ where $\mathbb{Z}[M]$ is the group ring $\bigoplus_{i\in M}\mathbb{Z}_i$ with an obvious ring structure. Note that $D_S(M)$ is always commutative no matter whether $M$ is commutative.

It's known in a few reference that if $M$ is commutative then $D_SD_S(M)=M_S$ i.e. $M_S$ is reflexive. (e.g. SGA3,Expose VIII,Page 3,Theoreme 1.2 or [Groupe Algeacutebriques by Demazure and Gabriel, Chap II,§2,2.11 Dualite des groupes diagonalisables]). But none of the proof seems convincing. And I seem to find a counterexample in some sense.
From my understanding of the corresponding between $\DeclareMathOperator{\itSpec}{\mathit{Spec}}D_SD_S(M)(T)=\mathrm{Hom}_{\mathrm{Gr}-T}(\itSpec_{\mathcal{O}_T}\mathcal{O}_T[M],\mathbb{G}_m)$ and $M_S(T)$. A element in $\mathrm{Hom}_{\mathrm{Gr}-T}(\itSpec_{\mathcal{O}_T}\mathcal{O}_T[M],\mathbb{G}_m)$ corresponds to a map of $\mathcal{O}_T$-algebras $f:\mathcal{O}_T[t,t^{-1}]\to \mathcal{O}_T[M]=\bigoplus_{i\in M}\mathcal{O}_T$ s.t. $\epsilon f(t)=1$ and $\Delta(f(t))=f(t)\otimes f(t)$.
If we write $f(t)=\sum_{i\in M}a_i\cdot e_i\in \bigoplus_{i\in M}\mathcal{O}_T(T)$ then we have $a_i \cdot a_j=\delta_{ij}a_i$ and $1=\sum_i a_i$ (so each $a_i$ is an idempotent element in $\mathcal{O}_T(T)$). Clearly $\forall s\in T,1|_s=\sum_i a_i|_s$ so at least one of $a_i$ is supported on $s$. And $T_{s_i} \cap T_{s_j}=T_{s_is_j}=T_0=\emptyset$. So $(T_{s_i})_{i\in M}$ forms a disjoint open cover of $T$ which can be identified with a locally constant function from $T$ to $M$. But the only problem is, $\sum_{i\in M}a_i\cdot e_i\in \bigoplus_{i\in M}\mathcal{O}_T(T)$  has only finite terms, which means the induced locally constant map has only a finite image. And I believe that there exists locally constant functions $T\to M$ with infinite image, which cannot be induced from $\mathcal{O}_T[t,t^{-1}]\to \mathcal{O}_T[M]=\bigoplus_{i\in M}\mathcal{O}_T$.
So which part of my arugments is wrong? Or do we need some extra conditions on $M$ (like finite or finitely generated) or the base scheme $S$ (like locally Noetherian, locally connected or connected)? Or the duality only holds in some topology like fppf/etale topology?
 A: I am going to give an identification of $DD(M)(S)$ and $M_S(S)$.
Using the identification $D(M)=\mathrm{Spec}\mathcal{O_S}[M]$ and $\mathbb{G}_m=D(\mathbb{Z})$, we have
$$DD(M)(S)=\mathrm{Hom}_{\mathcal{O}_S-\mathrm{Hopf-alg}}(\bigoplus_{i\in \mathbb{Z}}e_i\mathcal{O}_S,\bigoplus_{i\in M}e_i\mathcal{O}_S)$$
i.e. every element is determined by a map $\phi$ of $\mathcal{O}_S$-modules s.t. the following commutative diagram holds
$$\require{AMScd}\begin{CD}
\bigoplus_{i\in \mathbb{Z}}e_i\mathcal{O}_S     @>\phi>>  \bigoplus_{i\in M}e_i\mathcal{O}_S\\
@VV{e_i\mapsto e_i\otimes e_i}V        @VV{e_i\mapsto e_i\otimes e_i}V\\
\bigoplus_{j,k\in \mathbb{Z}}e_{j}\mathcal{O}_S\otimes e_k\mathcal{O}_S     @>\phi\otimes \phi>>  \bigoplus_{a,b\in M}e_a\mathcal{O}_S\otimes e_b \mathcal{O}_S
\end{CD}$$
It's equivalent to the data $\mu :\mathcal O_S \cong e_1\mathcal{O}_S\stackrel{\phi}{\to}\bigoplus_{i\in M}e_i\mathcal{O}_S$ (written $\mu=\sum_i e_i \mu_i$ where $\mu_i:\mathcal{O}_S\stackrel{\mu}{\to}\bigoplus_{j\in M}e_j\mathcal{O}_S\to e_i\mathcal{O}_S\cong \mathcal{O}_S$) s.t. the diagram commutes
$$\require{AMScd}\begin{CD}
\mathcal{O}_S     @>\mu>>  \bigoplus_{i\in M}e_i\mathcal{O}_S\\
@VV{\mathrm{id}}V        @VV{e_i\mapsto e_i\otimes e_i}V\\
\mathcal{O}_S     @>{\mu\otimes\mu}>>  \bigoplus_{a,b\in M}e_a\mathcal{O}_S\otimes e_b \mathcal{O}_S
\end{CD}$$
and $\sum_i \mu_i=\mathrm{id}$.
It's equivalent to the condition that $(\mathcal{O}_S\otimes \mathcal{O}_S\stackrel{\Delta}{\to}\mathcal{O}_S)\circ(\mu_a \otimes \mu_b)=\delta_{ab}\mu_a$ and $\sum_i \mu_i=\mathrm{id}$.
Over any affine open, we have $(\mathcal{O}_S\otimes \mathcal{O}_S\stackrel{\Delta}{\to}\mathcal{O}_S)\circ(\mu_a \otimes \mu_b)=\mu_a \circ \mu_b$. So it's equivalent to the condition that $\mu_a \circ \mu_b =\delta_{ab}\mu_a$ and $\sum_i \mu_i =\mathrm{id}$.
Claim: It's equivalent to the data {$(U_i)_{i\in M}$ is a disjoint open cover of $S$}.
Proof of the claim. Given a disjoint open cover $(U_i)_{i\in M}$ of $S$, then each $U_i^c=\bigcup_{j\neq i}U_j$ is open, there exist an unique element $c_i\in \mathcal{O}_S(S)$ s.t. $c_i|_{U_i}=1$ and $c_i|_{U_i^c}=0$ using axioms of sheaf. With each $c_i$ we can associate $\mu_i:\mathcal{O}_S\to \mathcal{O}_S,u\mapsto c_i u$. It's not hard to see that $\mu_a \circ \mu_b=\delta_{ab}\mu_a$. As $\sum_i c_i=1$, we have $\sum_i \mu_i=\mathrm{id}$.
Reversely for each $s\in S$, $\mu_{i,s}:\mathcal{O}_{S,s}\to\mathcal{O}_{S,s}$ is completed determined by $c_{i,s}=\mu_{i,s}(1)$. We know that $c_{i,s}c_{j,s}=\delta_{ij}c_{i,s}$ and $\sum_{i}c_{i,s}=1$. So each $c_{i,s}$ is idempotent ($x^2=x$), but the only idempotent elements in a local ring is $0$ and $1$. So exactly one of $(c_{i,s})_{i\in M}$ is 1.
For any $i$, denote $U_{i}$ as the subset consisting of $s$ s.t. $\mu_{i,s}=\mathrm{id}$. Then $(U_{i})_{i\in M}$ is disjoint. If $s\in U_i$, then $\mu_{i,s}=\mathrm{id}$, clearly it extends to an open neighborhood of $s$, see tag 01CP. Thus $(U_{i})_{i\in M}$ is disjoint open cover of $S$. The result follows.$\square$
Clearly the data {$(U_i)_{i\in M}$ is a disjoint open cover of $S$} is equivalent to the data {locally constant function $S\to M$}. The result follows.
