Your created indices will contain random indices in the range [0, len(dataset)] and will not be clipped by the length of the subset.
I assume that the returned index value is the index passed to __getitem__, so the behavior is expected.
If you want to pass indices in the range [0, len(subset)], you could directly pass these indices to Subset using torch.arange(int(n*0.5)).