If a new server sees you trying to connect, but doesn't know what your friend code is because it never assigned you one itself, it will try to assign you a new friend code, while your Wii is still trying to use your old one (which may have already been assigned to someone else by this new server). This is a problem for you, because the server is the one doing the assigning. The first time you connect to Wifi, your Wii is designated a friend code from Nintendo's servers. Your Wii knows what its corresponding friend code is, and will always attempt to log in with that friend code. The connection between your Wii and its friend code happens via a 'profile', which tells Nintendo's servers that wii A belongs to friend code B.
Friend codes for Nintendo Wifi games are assigned server-side.