How Account Name and Contact name are populated in Salesforce using Web to Case?

The contact name will be populated automatically if Contact is Existing with the "Web Email" into Salesforce otherwise it will be blank. If you wanted to populate the contact that is not existing then you have to do some customization using apex trigger.
Web to case should populate the contact field IF the email address already exists and it only exists once.

Make sure that the Web Name, Web Company, Web Phone and Web Email fields are on the Case pagelayout. These fields are what captures the Web-to-Case fields. Web-to-Case Name field is the Web Name field in your Org(Your Salesforce instance), Web-to-Case Phone is your Web Phone field in your Org, etc.

What happens is that if the information provided by the Web-to-Case form filler matches Account and Contact information in your Org the Contact Name and Account Name fields on your Case pagelayout will populate with the correct information.