What is the correct of operations for powering analog sensors from digital pins

One thing I've always wondered about is the correct order of operations for powering and then de-powering analog sensors from digital pins.

Say, for example, that I was driving a thermistor voltage divider from D9.

To power the divider, with the other end connected to GND, I can

pinMode(9, OUTPUT);digitalWrite(9, HIGH);

or I can do those two in the reverse order.

Similarly to de-power the sensor

digitalWrite(9, LOW);pinMode(9, INPUT); or I can do the pinmode input first.

It seems to work in either configuration, but I was wondering if someone here would know if there is a good reason to do those operations in an order different from the one I've shown here...?

If D9 has never been touched before, then it is in input mode at the beginning (after reset). Using your first proposed sequence

pinMode(9, OUTPUT);
digitalWrite(9, HIGH);

makes the pin "active", it will be internally connected to GND first, then switched to HIGH almost immediately.
If you swap the two lines, then the internal input pullup resistor will be activated first, pulling the pin "slightly" HIGH. Then the pin will be made active and pulled "really" HIGH.
For a passive sensor it does not make a difference at all. The distinction is only relevant if you are driving some sensitive input like a relay board involving an input amplifier. Making the pin HIGH first may transmit a HIGH signal although the pin is not yet an output pin.

If I was driving a mosfet/BJT from the pin, it sounds like that 'slightly-high" but not really high, situation could cause some weird results?

So I will stick with pinmode output ->digital write to enable a power supplying pin

and

digital write low -> pinmode input to turn off the pins

as the correct order

None of this is right. To turn off do:

digitalWrite (pin, LOW);

The interaction with the internal pull-up is completely avoided. Keep it as an output, for it is an output, no need to float the pin. If the sensor is down a long cable keeping the pin LOW will
potentially reduce noise pickup from it too.

Also don't try to power a whole chip with its decoupling capacitors from a digital output, that's going to have
big current spikes and needs proper switching with a PNP transistor of p-channel FET. A simple voltage divider
with < 1mA flowing is OK though.

Be aware that digital pin output drivers have about 40 ohms of internal resistance so are not
suitable for high accuracy work without taking that extra resistance into account. Something like
a 10k thermistor in series with a 10k resistor is reasonable though.

Thanks for clarifying that for me Mark. I had forgotten about the pins 'floating' when in input mode.

I have been pin-powering the RTC's on my loggers for a very long time now without apparent ill effects, but in that case its soldered directly to the IC leg, with no capacitors to worry about.

For my analog sensors, I always try to use higher value resistances (like a 100k thermistor instead of a 10k thermistor) so that those pin voltage drop errors are smaller by comparison.

EKMallon:
Thanks for clarifying that for me Mark. I had forgotten about the pins 'floating' when in input mode.

In your case, not even floating.
You have your voltage divider between the pin and GND. So if you set the pin to INPUT, LOW the pin will be pulled low by the about 20k resistance in the divider (assuming 10k NTC & 10k pull-up resistor).
Setting the pin to INPUT_PULLUP you enable the internal resistor, which tries to pull up the pin, and you'll end up at roughly 2V (30k internal and 20k external) on the pin.