The reason the hot one freezes first is because the hot one evaporates more, thereby lowering it’s mass. The amount of energy that must be removed from water to cool it is small compared to the amount of energy to freeze the water. Therefore, the mass of the water that freezes determines the total energy much more strongly than the starting temperature.