Better understanding of downsampling (decimation) and upsampling (interpolation)
There are few problems in the code and question. 

In your question 'given a sine wave at a given frequency for example, how would you proceed to downsample it to a lower frequency' this statement is not right. We are not reducing the frequency of sinewave, we are reducing the sampling frequency with which we sampled it.

Second, the code just inserts zeros alternatively. It doesn't downsample (means remove those samples altogether). This means, it is still sampled with original sampling frequency (8kHz) but now with alternate zeros. And what is the effect of alternate zeros in signal? It creates a replica of spectrum.
Also, in the code, the signal frequency is exactly half of sampling frequency, which causes sampling to happen at zero crossings. You can plot the signal $x$ and see.

In the code, I changed $f$ to 3000, and can see 2 peaks at 3000Hz and 5000 ($fs -  f$)Hz. For the downsampled signal, apart from original signal, there is 2 peaks corresponding to replicated spectrum.