Scientific explanations include that exposure to light, lack of moisture or absence of food can cause sporangia to form from the plasmodium. At least one of these three conditions has been present every time I've seen sporangia form.
Source: wiktionary