Since you haven't told us exactly how you set the printer up, we can only guess.
First - many printers allow you to connect to them through "WiFi direct" - with WiFi direct, as the name suggests, the printer and the PC are connected directly to one another, without the printer being connected to the WiFi network itself.
Second - WiFi security takes many forms, MAC filtering, WEP/WPA encryption, etc., - if we assume WPA (or one of it's variants), as this is the most commonly used, then the only way for a device to be connected is to have the encryption key entered, either manually, or via some sort of automated mechanism, for example the WPS system that many consumer grade routers have (a push button on the router).
It is also possible, if you are running the setup program from a device already connected to the WiFi network (which means the encryption key has already been entered), to export the key - this is commonly done with IoT devices, as an example, I've never entered a WiFi encryption key into my Samsung Smart watch, yet it connects to every WiFi network that my smart phone knows, because the watch is synced to the phone, I've also never entered in encryption keys into my current smart phone - when I upgraded from the previous phone, whatever WiFi networks had been configured on the old phone were automatically configured on the new phone.
Is your router secure? Sorry - I'm still trying to create an ip stack for my crystal ball - it's proving to be a little more challenging than I first thought.