It would appear the values of your function dy2dt are the 2nd column of your output variable X already.
If it is diff(dy2dt) you want to return (the 5th output), the error is because, inside your function, dy2dt is a single number, so taking the diff of it results in an empty matrix.
You don't use y(d) in the solution, so if you do need to take the diff, my suggestion would be to solve your ode, then take the diff of the resulting X(:,2).
[t, X] = ode45(@odeFun, tspan, ic, , param);
dy2dt_diff = diff(X(:,2))
function dXdt = odeFun(t, X, param)
dy2dt = (param.m2*y4^2*y1-param.k*y1+param.k*param.l0)/param.m2;
dy4dt = (-0.5*param.m1*param.g*param.l*sin(y3))/(1/3*param.m1*param.l^2+param.m2*y1^2);
dXdt = [dy1dt; dy2dt; dy3dt; dy4dt];