How does the detection of an IP location work?
There are databases that match the IP address to the geolocation and services that offer matching IP to its location. This GitHub project lists those services.
Getting a geolocation of an IP address is as easy as querying, for example: http://freegeoip.net/xml/22.214.171.124 and that's what the website you are accessing is most possibly doing (where the data comes from and its accuracy depends on the database).
The response is:
Is there a way to block (aside from a virtual network) websites from detecting locations?
This question boils down to "is there a way to hide my real IP address and appear as a one saved in the databases under a different location?"
Yes, as you already know it, you can do it mostly with VPN or some other routing/forwarding, but in either case you must (somehow) control the end-node.
You can also try using Tor network, however these nodes can easily be blocked by the server providing you the data (and likely the service providing the geolocation would indicate the request is for an IP being a Tor exit node).
How does the website tell its servers what info to load based on location?
Having obtained the location of an IP address requesting the data, it's just a matter of a simple query taking into account for example
City from the above result.