I know how it is controlled (photoperiodism), but I wonder why all plants don't start to flower in spring? Is it connected with ecological niche?
Why plants evolve to flower at various times depends on several factors. I've taken these from the book chapter Kudo 2006.
1) Climate and other abiotic conditions.
Spring, and the onset of consistent above freezing temperatures, is the first opportunity for many plants to flower, but it may not be ideal for all. For example some locations are still very dry in the spring and plants require water from rain later in the year.
Late frosts, which can damage flowers, is always a risk. Some plants can suffer the occasional frost and loss of flowers, while others hedge against this by flowering later.
2) Pollination competition.
For plants which are pollinated by animals (mainly insects), the finite amount of pollinators results in competition among plants for this resource. If all plants flowered at the same time competition would be extremely high, and no amount of animal pollinators could successfully visit every plant. Thus some plants have evolved to start flowering later in time and potentially have less competition. Note that other strategies to increase pollination from animals could also be to have larger and/or more numerous flowers.
Flowers eaten by animals are a waste of resources for the plant. For example if an insect preys heavily on flowers, and is most active during a certain part of the year, plants would evolve to flower outside of that time.
4) Seed maturation and dispersal
The ultimate purpose of flowers are to reproduce, and the timing of flowering can influence that. Plants with large fruit, such as berries, need ample time before winter to mature and this necessitates early flowering so that there is enough time for animals to disperse the fruit.
There are many limitations to everything above, and if a plant species evolves one strategy it generally limits itself in other aspects. For example the very first plants to flower in temperate environments may have low competition for pollinators, but they also risk being damaged by late frosts. A viable strategy may be to flower throughout the spring and summer, which some plants do, but they can only grow in environments with year round resources and likely cannot produce large fruit which animals can eat and disperse. Plants which flower in late summer or autumn likely need large roots to store the water and energy to do this.
Kudo, G. (2006). Flowering phenologies of animal-pollinated plants: reproductive strategies and agents of selection. In L. D. Harder & S. C. H. Barrett (Eds.), Ecology and Evolution of Flowers (pp. 139–158).