How does power remain constant when powering devices at different voltages?
The explanation for the scenario you are presenting is that the Wifi router has a switchmode DC-DC converter (likely a Buck Converter) inside which converts the input voltage of 12-24V into a fixed voltage needed by the other circuitry inside. DC-DC converters have the property that Pout = Pin * eff where Pout is the output power of the converter, Pin is the input power of the converter, and eff is the efficiency of the converter. For switchmode DC-DC converters typical efficiency is 80 percent or more, and only varies slightly with input voltage. For example it might be 82 percent at Vin = 12V and 78 percent at Vin = 24V. I just made up those numbers but they are kind of typical.
The input power is probably not perfectly constant. It is probably a little bit higher at 24 V than it is at 12V because the efficiency is probably a bit lower (if it is a buck converter, which it probably is).