This is implemented in the core and the core does know if the data being sent is a descriptor or raw data from RAM (vendor request). The USB core checks the bRequestType bits and parses the request to determine whether it is a vendor or Get_descriptor ( and also what type of Get_descriptor the SUDPTR is pointing to) request. Once it has determine the type of data the SUDPTR is pointing to the data is sent accordingly.
For a Get_config descriptor the data is send twice once with the Config descriptor only (9 bytes) and next time the whole descriptor along with all the endpoint, interface descriptors.
For a vendor request the data that is requested in the SETUP packet is sent over the USB.