Where do research labs get their funding?
Most labs get funding from granting agencies, governments, industry agreements, or private foundations. Some universities also provide funding in other forms.

Now, what they can do with the money depends on the conditions of the grant. Some, are attached to a specific project. They may also include a breakdown of the expenses: this much to hire two PhD students, this block to hire a posdoc, publications, experiments, computers... Some other grants are more open, and may give the PI more freedom to allocate the resources, or to work on sub-projects.

Some areas of research have economical interest, and may lead to patents and industrial agreements, that could help the lab to be less dependent on grants.

Lastly, some students may get their own funding, that may be attached or not to a specific project.

Universities do support labs, mostly by paying salaries of the staff and infrastructures.

Regarding the times, most labs apply to any grant in reach: you can never know if the grant you are hoping for will be renewed; and there is never too much money.