It seems like you should limit the target to just the rows with the same gID
as in the source, something like this:
with tgt as (
select *
from tableT
where gID in (select gID from @array)
)
merge tgt as t
using @array as s
on (t.ID = s.ID) and (t.gID=s.gID)
when not matched and s.ID < 0 then
insert into
when not matched by source then delete;