Are the id, the ego, and the superego necessary to evolution?
No. They are constructs used to explain human behaviors.
There may be other explanations or better models. In terms of “evolution” they would have to be generally present and relevant in all life forms. There may be an evolutionary development trend that moves from the Id to the Superego, but that again would be a result, not a condition of evolution.