Strategy as to when to apply to PhD programs I'm a master's student in CS at a top-20 school (in the US), in my second year (although it feels like my first year since I had to play catch-up last year and mainly took undergraduate courses).

My current strategy for applying to PhD programs is to apply only to top-5 this year, and if I don't get in, apply to a fuller range of programs (top 50 or so) next year. 

But because I don't have any publications in spite of having worked on 3 research projects, it doesn't sound like I have much of a chance of getting into top-5 programs this year anyway (and applying actually kind of sounds like a waste of time). So if and when I get rejected from them, I would take the next year to try to get a publication and also retake the GRE (my quantitative score is 164--in the 87th percentile when apparently the top programs expect a percentile in the high 90s).

However, although my GPA is 3.9 now, who knows what it'll be next year. Or if I'll manage to get a paper accepted. So does it make more sense for me to just try to get into whatever PhD program will take me now or to take a year to work on strengthening my application? As this post says, apparently the bar you have to clear to be considered an acceptable candidate rises every year anyway, suggesting that anything I do over the following year won't have much of an impact on my prospects.
Your chances getting accepted by applying out of the blue to top institutions is close to zero given that your application doesn't sound particular in any way. Most applicants GPA is between 3.8-4.0 and your GRE scores are ok. Start contacting some specific professors you would like to work with, even if not top-5, even top-10 or 20 will be better if you have a good research connection with a professor. Don't be obsessed with these rankings. If you have free time and money to throw away, sure, go ahead and apply now, but don't expect anything out of it more than the learning experience. You will also not get any feedback from the rejections, so you will never know why you were rejected.