You are assigning the first solution to the function y on the first iteration. When dsolve is executed again, y contains the first solution, and dsolve can't interpret that.
The answer is to use a different variable for the solution to the ODE, like so
y0 = -2:0.5:2;
y1 = -2:2:2;
syms y(t)
for q = y1
for k = y0
ysol(t) = dsolve(diff(y,2) + diff(y) - 2*y == t^2 - 4*t + 3,...
['y(0) == ',num2str(k)],['Dy(0) == ',num2str(q)])
end
end
Also, it is inadvisable to use i as a loop variable, even though it works in this case.
Many thanks to slitvinov, who helped with this problem on StackOverflow.