Science spacecraft are custom-built, instruments tailored for the specific mission (and the mission custom-tailored to the available instruments - it's a inter-dependent process), taking into account the special requirements of (deep) space like resilent to large temperature variation, radiation-hardened, vibration-proof (during the launch) etc.
Usually the major space agencies make a call-for-proposal where teams of scientists submit a proposal for a mission along with the purpose of the mission, and drafts for the mission timeline and the needed instrumentation, arguments and proof that it is technically feasible, and where and who shall build them or at least supervise the building of the single instruments from the science side.You can see the studied proposals on the space agencies websites, e.g. here for ESA. As students there are cheaper opportunities which involve less long-term planning, but still you go through these phases on the fast track, like here from ESA.
These proposals are evaluated by the agencies and other scientists, and then a ranking of the submitted proposals is done - and the best (by whatever scientific and political criteria) are funded. Then the actual work begins and the winning teams have to actually start working on it, usually jointly with industry which receive a request for tender and the winner is contracted with detailed plans of what to build and a long list properties the instrument must fulfill and of verification criteria.
General requirements (e.g. some general mechanical ones like these):
3.4 Interfaces Requirements
3.4.1 Launcher Interfaces
3.4.1.1 The XXX flight hardware shall be compatible with the launch environment of SpaceX Dragon and Northrop Grumman Cygnus as defined in SSP 50835 [AD4].
3.4.1.2 The XXX flight hardware shall be launched packed in foam in non-operating, non-powered condition.
3.4.2 Spin Load
The XXX Experiment shall be designed to withstand a roll rate at burnout of 8.0 Hz +/- 1 Hz at burnout of the motor.
Note: The static loads caused by the spin of 8 Hz can be calculated depending on the radius where the components of the experiments units are assembled.
Note: At motor burnout the linear acceleration will be at maximum.
etc etc and down to the individual parts, like cameras and optical setups where the requirements and performance matter:
3.2.9.3
The system shall have a resolution of at least 10"/pixel within the FOV.
Beginning of Note: The system does not need to resolve particles, only detect them. End of Note.
3.2.9.4 The system shall have a frame rate which is fast enough to allow for the tracking of the particles.
3.2.9.5 The exposure time shall be such that it matches the speed of the particles at the given illumination levels in order to avoid blurring.
3.2.9.6 The system shall be operated according to the reference experiment protocols defined in Section 4.1, in particular for what concerns operation durations and operations with other devices.
3.2.9.7 The two cameras shall be synchronised with each other. The simultaneousness shall be better than half of the inverse of the frame rate for frame rates of >10Hz and 0.05 sec for frame rates <10 Hz.
3.2.9.8 The sensitivity of the system shall be sufficient to detect the particles listed in Table 1.
Things like this are not available at your favourite home depot store.
Once the hardware is defined, the mission profile with detailed usage of instruments is discussed and agreed-upon often long before launch. The sequence of tasks is discussed and set in meetings with all involved scientists from all instruments and from flight dynamics (those who run the engines, telemetry home etc) - to find the scientific most promising way to operate the spacecraft given power, telemetry, fuel, spacecraft orientation, data storage and other limitations. Usually timelines are written down to the second, especially for the important maneuvers. Of course, as science advances and new opportunities arise, some things can be subject to change. Especially long missions don't do the detail planning of instrument use during the mission, but still year(s) in advance - possibly with some time at disposal by lead scientists to decide on short notice depending on circumstance.
So long story short: instruments are usually purpose-built, and only some parts will be off-the-shelf, if they fit the criteria. During the mission, all available data are gathered within the limitations of power, temporary storage and downlink bandwidth. You cannot modify the instruments once they're in space, you can at most change what the spacecraft looks at. But as instrumentation is purpose-built with a specific mission design in mind, other completely different uses often are not making good use of the ressources. If trade-offs in observation need to be made, this is discussed and decided in meetings of all involved parties who have instruments on board of the spacecraft, often long ahead of the actual time these observations are done.