It is not possible to give you an answer to your question that covers the exact details because there are a range of different technologies in use for smart devices. I will list a few of them here:
1) Some smart devices use proprietary wireless RF connections to a hub device that then in turn connects to your network. The hub knows how to search for devices to establish pairing via the RF connection. Often the pairing requires placing the smart device in a pairing mode so it announces itself to the hub. Setting up the hub on the local network will typically use a wired connection and get an IP address via DHCP.
2) Some smart devices use a proprietary communications protocol over the power line to a hub device that then in turn connects to your local network. Operation is similar to as described in (1) above.
3) Other smart devices have a full WiFi end point built right in. These devices are most often configured by using an App in a smart phone that talks to the smart device using a separate protocol from the phone over Blue Tooth. The smart device is typically initially placed into a Blue Tooth pairing mode and the App on the phone automates the pairing. Information about the WiFi connection is passed from the App to the smart device via the paired Blue Tooth connection.
4) There are smart devices that have a full WiFi end point built in but also have a display and buttons or a touch screen. WiFi connection information for these is entered directly into the device via this user interface. This is often seen with smart thermostat units.
5) There are a class of smart devices that have the WiFi end point but also have a USB connection. The USB connection is attached to a laptop or PC and used in a setup mode with an App on the laptop or PC to configure the WiFi connection information in the smart device through this USB interface. This type of setup has been common with some types of WiFi access routers.
6) Yet another class of smart devices that have a WiFi interface can be placed into a setup mode by pressing a button or switch. Often an LED will blink to show it is in the setup mode. In this mode the smart device acts as a WiFi access point and advertises a specific SSID. An app on a smart phone makes the phone search for that SSID and will temporarily connect the phone to that access point. Once connected the App can configure the smart device according to the SSID and password for the local network. An example of this scheme can be found in the more recent models of the Sonoff Wi-Fi smart switches.