See Frame Counters in https://www.thethingsnetwork.org/docs/lorawan/security.html, in which the following is circumvented by using TTN’s “reset frame counters” option:
Therefore, you should re-register your device in the backend every time you reset it.
(See also some notes about TTN Console’s Frame Counter Checks option.)
Also, devices don’t connect to a gateway. The just transmit and hope one or more gateways receive their packet, and forward that to TTN.