It took me a while to come up with a way to do this without looping, then it clicked! You need to create groups based on where the 0s are. To do that, flip the logic of the counter and cumsum that:
t.ResetGroup = cumsum(~t.Counter);
Then, you can use varfun to group by both ID and ResetGroup and do the cumsum.
t = varfun(@cumsum, t, "GroupingVariable",["ID","ResetGroup"])