The server allocates storage for each client and ties it to an identifier. For web sessions that identifier is usually a session ID stored in a cookie; the server keeps the matching session data in memory or in a store like Redis. For long-lived connections like TCP, WebSockets, or a database connection, the state is the connection itself: sequence numbers, buffers, authentication context, all held in the server process.
Because the state lives on one specific machine, requests from the same client normally have to return to that same machine. This is called session affinity or sticky sessions, and load balancers implement it by hashing the client IP or reading a session cookie so they always route a user back to the server that holds their data.
If that server crashes or restarts, the in-memory state is gone. The user gets logged out, the cart empties, the game disconnects. This is the core operational cost of statefulness: the data has a home, and losing the home loses the data unless you replicate or persist it elsewhere.