Data is crowdsourced and contributed by users. On a much larger scale, Apple and Google collect data from iOS and Android devices to power their WiFi/mobile tower based geolocation services.
Mozilla also has such a service although I believe they're deprecating it. You can still query it today, but as a privacy measure you need to include the MAC of 3+ SSIDs to get location info, since otherwise you could check the SSIDs from probe scans of passerby to locate their homes.