The service used by the iPod touch is powered by a company called SkyHook.
SkyHook does not restrict itself to "official" public WiFi hotspots. Instead, it sends a fleet of vehicles down every navigable street within a covered area, scanning ALL of the WiFi access points in the vicinity (both private and public) and recording their unique signatures (called a MAC address, but it has no relation to the popular computer platform) along with their signal strength at various latitudes and longitudes.
Whenever the WiFi radio is turned on and CoreLocation is in use, the iPod touch continually scans the MAC addresses and relative signal strengths of all the WiFi access points in the vicinity (not just the one it happens to be connected to), and queries those MAC addresses in SkyHook's database. It can then use those results to triangulate your approximate location.
If SkyHook's database doesn't contain an entry for the WiFi access points nearest you, or if the WiFi access point has moved since the last time SkyHook refreshed its database, then the iPod touch will provide incorrect location information. In that case, it is also possible for operators of WiFi access points (including owners of private home networks) to submit new information to SkyHook in order to help them improve their coverage.