Map from Google - Cancun

In Cancun, located just north of the Riviera Maya, in the Mexican state of Quintana Roo, the climate is tropical, with a muggy and rainy season from May to October, and a cooler season, and also relatively dry, from November to April. However, also in the latter season, rainfall may occur, in addition to wind and cloudiness, especially in December and January.
The average temperature ranges from 24 °C (75 °F) in January, to 29 °C (84 °F) in the period from June to August. Here are the average temperatures.
Average temperatures - Cancun
CancunJanFebMarAprMayJunJulAugSepOctNovDec
CancunJFMAMJJASOND
Min (°C)212122232425252525242321
Max (°C)282930323333333433313028
Min (°F)707072737577777777757370
Max (°F)828486909191919391888682

Precipitation amounts to about 1,350 millimetres (53 inches) per year, with a minimum in March and April, and a maximum in September. Here is the average precipitation.
Average precipitation - Cancun
CancunJanFebMarAprMayJunJulAugSepOctNovDecYear
CancunJFMAMJJASONDY
Prec. (mm)6555354011018513015022518585801345
Prec. (in)2.62.21.41.64.37.35.15.98.97.33.33.153
Days65337121213141377102

The dry season, from November to April, is warm, with pleasant temperatures, and a warm sea in which you can swim. However, in November hurricanes and tropical storms can still pass (see below), while from late November to early March the wind from the north, called el Norte, can blow, bringing cool and windy days, with highs around 22/23 °C (72/73 °F) and lows around 13/15 °C (55/59 °F), and also clouds and some rain.

The rainy season, from May to October, is hot and above all humid. The breeze tempers a bit the heat, but moisture is very high. There's no shortage of sunshine, because the rains occur mainly in the form of showers or thunderstorms, short but intense.
The main danger comes from hurricanes, which can be devastating, although fortunately they are relatively rare. The hurricane season runs from June to November, although they are more likely from August to October.

The amount of sunshine in Cancun is never great, but not even poor. The sunniest period goes from March to May, ie after the season of northerly disturbances, and before the season of hot weather and thunderstorms.

Cancun

For swimming, the sea is warm all year round, as we can see in the following table.
Here are the average sea temperatures.
Sea temperature - Cancun
CancunJanFebMarAprMayJunJulAugSepOctNovDec
CancunJFMAMJJASOND
Sea (°C)262626272828292929292827
Sea (°F)797979818282848484848281

When to go

The best time to visit Cancun runs from mid-March to late May, being a warm period, relatively dry and with frequent sunshine. In April, a bit of sultriness begins to be felt, and in May the first thunderstorms can occur. In winter, from December to mid-March, you may very well find a warm and sunny week, but at other times there may be a few days with wind, clouds and some rain. Until March, when the Norte can blow, it can be cool at night, so it's better to bring a sweatshirt for the evening.