If your treatment is covered by insurance then you will need to check with the insurance company if they will cover an extended stay in Costa Rica. If you are paying privately for your treatment, then the additional accommodation, appointment costs and any flight changes will be paid by you.
It is best to check with your treatment provider before coming to Costa Rica what is the required time to stay in Costa Rica following your treatment as the treatment provider will need to confirm you are fit to travel before you fly from Costa Rica.