You are close. You need to use findgroups to create your grouping variable G. Then it's just a matter of setting up your function handle correctly. Here's your code with a slight modification from me. If you compare the results, you'll see they are the same.
%%Generate some data
X1 = 10 + 5 * randn(200, 1);
X2 = 20 + 8 * randn(250 ,1);
cat1=repmat("a",200,1);
cat2=repmat("b",250,1);
X = [X1; X2];
cats=[cat1;cat2];
%%Fit a distribution using a kernel smoother
myFit1 = fitdist(X1, 'kernel')
myFit2 = fitdist(X2, 'kernel')
% Now use findgroups/splitapply
G=findgroups(cats);
newfit=splitapply(@(X)fitdist(X,'kernel'),X,G);
newfit(1)
newfit(2)