When a choice is available, YOU do:
This is a screenshot of my phone when it is plugged into another USB-C device. I can pick whether to charge my phone via that device, or send power to it. In this case I plugged into a Macbook Pro, and I can confirm that my phone will (attempt to) charge the laptop (as far as the laptop showing the “charging” battery symbol anyway, I doubt it’s actually pushing any useful power through though).
This dialog is only available when a choice can be made. In most cases however, your devices will auto-negotiate based on each device identifying what it is connected to (including whether it is USB-C power delivery compliant, and whether it has a power supply). If a phone is plugged into a charger, then it’ll always charge; or a laptop will always supply power unless the device connected to it identifies as a power source. A USB-C hub may or may not have an external power adapter attached, and the ones that’ll charge your laptop will be able to notify your laptop of this fact.