Well, that's because Galileo doesn't really re-initialize the network each time you restart the sketch. Network is configured, as it is usually in UNIX, during the board boot process and sketch just uses the existing connection. And due to that fact, the DHCP->static switching is possible on the fly (as well as trying different static IPs), but static->DHCP would require restarting the DHCP daemon on the board.
But you still can do this from the sketch, though that won't be your conventional Arduino aproach. You'd need to issue the restart command to DHCP daemon using the system() function. Probably the simplest way would be to restart the "networking" service, which would take care of all the things.
That would restart the networking subsystem and it will get back to the DHCP (provided you haven't changed anything in the default network setup).
Hope this helps.
Well I think that this can be managed by firmware (on-board Linux itself?) when new sketch is loaded, either rebooting network on new sketch or by matching the sketch configuration (eg. if sketch is in DHCP, check if daemon is running; else stop daemon if running and setup fixed IP).
I know that this can be an unusual condition (and this behavior is noticeable only when flashing), but I think that Arduino-like approach is better than actual "mechanism"/"workaround" (you called this board "Arduino Galileo"...).
Make no mistake - I'm not saying the current behavior is good or the only possible :-) I just wanted to help you get past that problem and explain what the reason is.
I think what you describe should be doable and indeed would bring the actual behavior closer to the one demonstrated by native Arduino libraries, which should be a good thing for sure. Hopefully that will get corrected in future releases.