Holometaboly isn’t a “trait” that appears randomly though, it’s an entire system of evolutionary specializations that developed because of strong pressure towards evolving that way.
Hemimetaboly is the default, less derived state, and it persists because it is no disadvantage to insects that still use it (and, of course, is also likely an advantage to those with certain ecological roles). Holometaboly is the derived state that developed because it had a clear and distinct advantage to the ancestors of groups that do use it.