algebraic geometry – Duality of diagonalizable/constant group scheme?

Let $M$ be an arbitrary abstract group and $S$ be a scheme. Let $M_S=coprod_{iin 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 tin T,exists Uni ttext{ 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/Smapsto 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)$. 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_{iin 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_{iin 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_{iin M}a_icdot e_iin bigoplus_{iin 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 sin 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})_{iin 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_{iin M}a_icdot e_iin bigoplus_{iin 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 $Tto M$ with infinite image, which cannot be induced from $mathcal{O}_T(t,t^{-1})to mathcal{O}_T(M)=bigoplus_{iin 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?