If the weather is important to you, then the best months to visit Beijing are April, May September and October. Beijing has hot, humid summers and cold, dry winters. In spring and fall the temperatures are pleasant and the sky is clear.
However, if weather is not a factor, there is no really bad time to visit Beijing. Beijing is a huge city with so many opportunities for the traveler. Consider what you would like to see in any major city in the world. If seeing beautiful gardens is an activity you love, then summer is perfect. Perhaps you have always wanted to be part of the real Chinese New Year; then a visit in winter might be right for you. Visiting during a less traveled time of the year can provide many advantages.