Using sinc as a filter I'm trying to use a cardinal sine as a lowpass filter for a cosine signal with a fundamental of 1k. 

In frequency domain, what really happens is that I'm multiplying two impulses (centered at -1k and 1k) with a rectangular pulse of width equals 2 (convolution is multiplication in frecuency domain). The result would be a constant zero function. However using the above code in Matlab I'm getting again the sinc function as output. Any help would be appreciated (attached the full plot).

D = 5;
f0 = 1000;
fm = 2*f0;    % nyquist reestriction

t = (-D:1/fm:D);
x = cos(1000*2*pi*t);
h = sinc(t);

x_p = filter(h,1,x);
plot(x_p);
You messed with f0/fm relationship. Try this code:

D = 5;
f0 = 1e3;
fm = 40e3;
t = 0:1:2*fm*D-1;
x = cos(2*pi*t*f0/fm);
h = sinc(-D*pi:1/10:D*pi);
x_p = filter(h,1,x);
plot(x_p); plot(x); plot(h);
figure; psd(x,2^11,fm);
figure; psd(h,2^11,fm);
figure; psd(x_p,2^11,fm);