Let’s consider an example, your company needs technician or an employee for a specific task, instead of hiring the person for the full period and putting so many efforts in keeping on pay for a continuous period, companies can instead look for staff for that specific work and time. Paying only for that amount of work efforts is more cost-effective than hiring a person for full time.
Outsourcing is also done for the products. For examples companies like Pepsi, coco-cola outsource their bottles from the third party and do the rest work in-house. This way the production and fluency are faster. Same is for many IT sector companies.