This is stupid code. First I rewrite it so that this becomes obvious (I add quoting, too):
for j in *.* ; do
target_file="../../$name-S$i.gid/data/${j%%.*}$i.${j#*.}"
cp "$j" "$target_file"
sed "s/$name-S/$name-S$i/" "$j" >"$target_file"
done
I.e. a file is copied and immediately afterwards the new file is overwritten. This is done for all files whose name contains a dot (but probably not at the beginning; depends (in bash) on the setting of dotglob).
The target file path is constructed as:
Put it in another directory.
Erase the file extension (all parts of it, i.e. everything from the first dot).
Add the number i and then the old extension.
The sed call replaces only the first (intentional limitation?) occurrance of $name-S (i.e. its expansion) in a line by $name-S$i (its expansion again).