During the registration of a domain name, the customer provides the registrar (directly or through a reseller) with their full and complete contact information, notably their full name (and/or the name of their company, association, etc.), street address, email address, phone number, etc. The registrar includes this data with the domain registration request sent to the registry, and accompanies it with technical information about the domain such as what nameservers will be used, whether or not DNSSEC is enabled, what statuses it will be assigned, etc.
The WHOIS protocol is therefore used to query the database of the registry or registrar in order to ask for current information about a specific domain name. If the domain name has been registered, and therefore exists in the database, it will return the public data on record for that domain.