The first message from the server to the client (ServerHello) includes a random challenge which changes every time. The client proves that it knows the private key corresponding to its certificate by sending a signature (CertificateVerify) of all the handhsake messages received so far, including the random challenge. A third party that doesn't know the private key can't replay the connection, because the server will send a different random challenge each time.
The mechanism is exactly the same in the other direction. The client's first message also contains a random challenge, and the server must sign data that includes this random input. (That's in cipher suites that use signatures for authentication. In cipher suites that use asymmetric encryption or pre-shared keys, the server instead proves that it can decrypt some data that depends on the random challenge.)
You can see the details of a typical TLS connection in The Illustrated TLS Connection: Every byte of a TLS connection explained. The server's signature is at the end of the “Server Key Exchange” step. This example doesn't use client authentication; if it did, that would be an additional part in “Client Key Exchange” with similar content.
If you want all the details, they're in the specification. The term to look for is CertificateVerify
. RFC 5246 §7.3 (TLS 1.2) and RFC 8446 §2 (TLS 1.3) have a summary of the handhske protocol. RFC 5246 §7.4.8 and RFC 8446 §4.4.3 give the content of the CertificateVerify message.