[OT] Strange Arduino IDE problem

I know this isn't a node-red issue, but possibly someone here can help me out with a very odd issue.
I am using the Arduino IDE to program a Wemos D1 Mini, which I have done before. I want it to have a fixed ip address so I have

IPAddress staticIP(192, 168, nn, 65); //ESP static ip
IPAddress gateway(192, 168, nn, 1);   //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0);  //Subnet mask
IPAddress dns(192, 168, nn, 1);  //DNS

Then in setup_wifi() I have

  WiFi.config(staticIP, subnet, gateway, dns);
  WiFi.begin(ssid, password);

and everything works perfectly. However, and very strangely, if I specify 192.168.nn.66 for the ip address it ends up with nn.107 which is in the DHCP range. 19.168.nn.67 also works ok. I have looked in the router and can't see anything there that looks relevant.

Can anyone suggest anything or must I just resign myself to not using that address?

Edit: I have tried configuring a PC with .66 as the ip and it is ok, so it seems it is an Arduino ide issue. Google has not been helpful.

Have you perhaps in the router configuration associated the PC MAC address with .66 at some point in the past? That's the only thing I can think of!

My EE Router has this option:
Opera Snapshot_2021-02-18_180122_192.168.1.1

Isn't it WiFi.config(staticIP, dns, gateway,subnet) , different order then you have.

Edit: Confusing, for the ESP8266 you see indeed WiFi.config(staticIP, subnet, gateway, dns) on the various forums.
I'm using myself in a working project WiFi.config(ip, gateway, subnet, dns1, dns2);

Plus it works fine with other addresses, and on the other Wemos I have had working for some time. It is only 66 that gives the problem.

Can you ping that .66 or have you tried a netscan tool to check, whether .66 is indeed free?
Which router do you use? My AVM Fritzbox has some IP addresses it reserves as soon as I configure VPN connections (but reacts not the way you described).

Brilliant, well spotted, though it is even more complex than that. The Arduino function expects ip, dns, gateway, subnet but the config function for the ESP8266 expects ip, gateway, subnet, dns. To cope with this (presumably accidental) situation there is a function ipAddressReorder in the ESP library that examines the parameters and attempts to work out which is being used and swaps them round if necessary. If it finds values that don't seem to fit either pattern then it returns false to indicate a failure.
Unfortunately I actually had ip, subnet, gateway, dns which I must have picked up from a tutorial somewhere and is wrong on all counts. It turns out that with the ip .66 the swap functions recognises there is an error and fails, causing DHCP to be used, but with .65 it thinks everything is ok, and uses that address. The gateway. subnet and dns were not right, but since I am only using it to communicate within the local network the gateway and dns don't matter, and provided the subnet is compatible with the ip it will work ok.
So I have corrected it to the correct ESP format (IP, gateway, subnet, dns) and in addition added a test on WiFi.config that checks for a false return and logs a warning if so. I have also added comments explaining the situation so that hopefully I won't fall over it again.

Thanks to @edje11, @ghayne and @stefan24 for the help with this.