There are a number of different theories about why hot or boiling water can freeze faster than cold water in certain situations, including thermal contact from the warmer container. One of the more recent explanations indicates it has to do with the special nature of the hydrogen bonds in water.
In 2013, a team of researchers at Singapore's Nanyang Technological University showed that warmer water contains longer hydrogen bonds, which release energy as they shrink during cooling. This speeds up the cooling process, allowing the warmer water to freeze faster under certain conditions. The special effect of these hydrogen bonds also is thought to be what gives water many of its other unique properties, such as its high boiling point and the fact that it is less dense as a solid than as a liquid.
This effect of hot water cooling faster is known as the Mpemba Effect, which was named after Tanzanian high-school student Erasto Mpemba. In 1963, Mpemba showed that a hot ice-cream mixture froze faster than a cooler mixture. He showed this idea to a professor, and the two subsequently published a paper on this effect in 1969. Although Mpemba is given modern credit for the discovery, this effect has been observed by numerous famous scientists throughout history, including Aristotle, Rene Descartes and Sir Francis Bacon.