imhistmatch() operates on pages of a 3D array independently. For two images with the same number of pages, each page is matched to the corresponding page in the reference image. If the two images have a different number of pages, one has to ask what the expected correspondence is.
Say the reference image has 10 pages and the input image has 8. You could simply use referenceimg(:,:,1:8). While that might work, would it meet the expectations? Is it okay that the last pages of the reference have no influence over the output?
What if the reference has 8 pages and the input image has 10? Now what's the reference for page 9 and 10?
Or is it expected that the intensity distribution of the entire image volume is considered as a whole? I imagine that's what is expected here. In that case, just reshape the images into 2D arrays, do the matching, and then reshape the result back into a volume.