Why do plants create enough energy for the entire ecosystem?
Plants collect energy for themselves via photosynthesis, not for others. 
It is used for it's own growth and survival.

It's energy is then redistributed to other organisms when either the plant dies and decomposes or when it is consumed. Many organism cannot collect their energy like plants do, and thus must feed on organisms (like plants) that are able to collect and store energy. This is in many cases detrimental to the plant (it should be intuitive why being eaten might be bad), and many, many plants do have traits to discourage other organisms from eating them (plants with toxins, thorns, etc.).