time invariance concept?
You do get a time-invariant response. Your code produces the same output for all three signals. In particular, it produces the same output for $y(\sigma^T\{x(t)\}))$ as for $\sigma^T\{y(x(t))\}$ (plots 2 and 3 in your code). It is hard to see in your case because you have shifted the signal $3\cdot 2\pi$ in time. Whats a cosine shifted by $6\pi$? The same cosine. Everything will be clearer if you plot the signals on top of each other and shift by a more informative value.

Try this code:

clc
clear all
close all
t=0:.001:10;
x=cos(2*pi*t);
y=x.^2;
plot(t,y)
hold on;

plot(t+0.25,y)

xn=cos(2*pi*(t-0.25));
y2=xn.^2;
plot(t,y2)

legend('y(t)','y(t-3)','y[x(t-0.25)]')

hold off


You can see in the attached image, the orange and red lines, corresponding to shifted output and output on shifted input respectively, align with each other. That is why you can not see the red line up until the orange line ends. The unshifted output of the unshifted signal in blue does not align with the two other.