How does that person connect to my network automatically if he/she is
not connected to any network in the first place?
From Wi‑Fi Sense FAQ in section What does Wi-Fi sense do?, it says that your friend can connect to your network only after he has shared at least one network with his contacts.
How will my Wi-Fi key be sent to that person's machine before even
connecting to the network?
It comes down from a Microsoft server in encrypted form, and is decrypted behind the scenes.
He won't receive it until he tries to get connected to your network. I think it is better if I quote you directly this from the FAQ I mentioned. It shows how Wi-Fi sense determines available Wi-Fi hotsports to which your friend may connect to your shared network:
Wi‑Fi Sense has a database of information about open Wi‑Fi
hotspots—and we update that crowdsourced information based on what
your PC and other participating customers' PCs tell us about those
networks. Wi‑Fi Sense analyzes some characteristics of open Wi‑Fi
networks that other Windows customers have connected to and determines
if they had a good-quality connection. If enough of them did, those
networks are added to the database and are suggested by Wi‑Fi Sense.
You and others then get connected to a suggested network when one of
them is in range.
The very detailed process is not something Microsoft will publish.