The original USB standard was (is) indeed for 5V, at a maximum 0.5A, for a total of 2.5W. There is no logic involved--just connect to the pins and draw power.
As the USB interface has grown in sophistication through USB 2.0, 3.0, etc., options to draw more power from the interface have been introduced. Additionally, some devices have their own proprietary power standards implemented that are above and beyond the base USB specification.
In general, for the higher-power options, the receiving device and the powering source use some communications logic to perform handshaking when the connection is established and negotiate for a mutually-compatible power delivery arrangement. That is why you have to be careful to select a power adapter that supports a power delivery standard that your power-receiving device is compatible with. It is quite possible to have a power supply that can provide 25W and a device that can consume 25W but because the standards they use to do so are not compatible, the devices end up negotiating to a lower-common-denominator capability that supports only 10W. (I'm making up those particular numbers, but the general point is valid.)
It's also why I regret installing an expensive USB power port in my plane when I had the panel redone ~10 years ago. Charging standards have advanced dramatically since then and now neither my phone nor my tablet can charge at their fastest rate using that source. Fortunately, I also installed extra cigarette lighter ports, and over the years I've just purchased more-capable cigarette lighter power adapters to keep up with the times.