I guess you are doing segmentation…so rather than resizing, crop-pad is more appropriate. Since, the max size is 23 (in 0th dimension), you can pad the other images using np.pad
seg = np.pad(seg, [(23-seg.shape[0], 0), (0, 0), (0, 0)]) # pads in the 0th dimension
T2W = np.pad(T2W, [(23-seg.shape[0], 0), (0, 0), (0, 0)])

before appending into data1 and gt.