In practical terms, as an early-career researcher, the length of projects is determined by your funding. Whe the fundings runs out, you either ask for more or have to change project. If you finish the goals of your project early, there are always other interesting things about your project that you can explore.
It comes down to a combination of the subject, the funding and when a study is ready to published in a research journal.
Funding is required to keep the research going. It pays for equipment, chemicals, cells and the researcher’s salaries. To get funding you need to publish your research often in order to show that you can be successful with the money.
In some cases when a study is ready to be published, the lab might decide to draw a line under the research and move to a new topic when the research has been published (I’m kind of doing this now at the end of my PhD). Others may decide to keep the research going and follow the topic in more depth with further updated studies.
How long a study lasts really depends on the field. In my case I was really really lucky to publish a paper in three years and that was because everything seemed to fall into place for me. Other fields can produce papers faster or more often, it really just depends on the science.