Most thermostats have trouble connecting because they're too far from your router or there's something blocking the signal - try moving your router closer temporarily, or better yet, move the thermostat's location if you can during setup. Even a few feet makes a huge difference with WiFi, especially if the thermostat's buried in a wall or behind metal ductwork.
Before you assume it's defective, check a couple other things. Make sure your 2.4GHz band is actually broadcasting its SSID (some routers hide it by default, and thermostats can't find networks they can't see). Also verify you're entering the password correctly - these devices are picky about capitalization and special characters. If your router uses a really old security standard or is set to 5GHz only, that'll kill the connection too, though you said it's on 2.4GHz so that's probably not it.
If it still won't connect after trying different locations and confirming your network settings, there's a chance it genuinely is defective, but it's worth doing a factory reset on the thermostat first (usually there's a small button you hold for 10+ seconds). If nothing works after that, contact the manufacturer - they usually have decent support for this stuff and can either troubleshoot remotely or send a replacement. Defects do happen, but signal issues are the culprit in most cases.