In short, it usually happens when hot moist air gets trapped under cold dry air when the 2 fronts meet ie a summer thunderstorm. Rain water rises to altitudes where it freezes. They clump together and updrafts keep the the clumps in these altitudes. The size of the hail depends on how strong the updrafts are until they are so heavy they fall.