Plain s_client connects even when the certificate is wrong. It prints a verify error somewhere in the output and carries on, which is easy to miss.
Two options make it strict. -verify_hostname checks the certificate against a name, and -verify_return_error aborts the handshake on any verification error:
echo | openssl s_client -connect example.com:443 -servername example.com \
-verify_hostname example.com -verify_return_error -brief
With a good certificate you see Verification: OK and the connection details, and the exit code is 0. A name that is not in the certificate gives verify error:num=62:hostname mismatch, an untrusted chain something like unable to get local issuer certificate, and the command exits with 1.
I like it as a quick check before switching DNS to a new server: connect to the new IP with -connect 203.0.113.10:443, but keep -servername and -verify_hostname on the real name. Then you test the certificate the new machine will really serve.
Trust comes from the CA store OpenSSL was built with, which may not be the one your browser uses. For a private CA add -CAfile ca.pem. The name check needs OpenSSL 1.1.0 or newer. And note that -servername only picks which certificate the server sends; -verify_hostname is the option that actually checks it.
Further reading: OpenSSL: openssl-s_client, OpenSSL: verification options