This may be a naive question. When I type in a .onion address I assume that the Tor network is designed to not know the ip of the server, or else law enforcement could easily subpoena Tor saying "Hey this .onion has illegal content, what's it's ip?". So how can the Tor network connect to the ip address of a hidden network without knowing the ip?
The general idea is that the client doesn't connect directly to the onion service. Instead, the client creates an anonymous circuit to a relay, the onion service creates its own anonymous circuit to the same relay, and the relay attaches/splices the two circuits together. So the onion service is actually making a TCP connection out to the Tor network, rather than having the Tor network make a TCP connection to the onion service. The Tor network itself doesn't really need to care about the onion service's IP address.
A good summary of the process can be found in Section 1.1 "View from 10,000 feet" of the Tor Rendezvous Specification document.