Any time is great for a visit to Cancun. The summer months are more humid and warmer, with highs in the upper 80s F/20s C, but the sea breeze keeps you cool. It seldom rains in the winter. Hurricane season runs June-November, and that's when rain is most likely.
Cancun is especially popular in March and April as a spring-break destination for college students from the U.S. Mexican tourists flock to Cancun a week before and after Christmas, the week of Easter and in July and August. Make reservations early for those times.