In more detail
The browser checks the server's Digital certificate and then encrypts everything with TLS, so people on the same Wi-Fi cannot read or change what you send. The padlock means the connection is secure, not that the site is trustworthy. HTTPS is also required for many browser features and is a minor search ranking signal.