An apple pie can sit out overnight at room temperature.
Leaving an apple pie out overnight is safe but any longer than overnight then the apple pie should be refrigerated.
I've safely left apple pies out overnight and it's been okay.
But if you're not eating the apple pie within a day then it should be refrigerated or frozen.
Pies such as pumpkin pie should be refrigerated if not eaten within 2 hours.
Most people recommend refrigerating apple pies or any other types of pies within 2 hours of baking the pies to prevent any bacteria from growing on the pie.
I've noticed apple pies and other pies out in the open at room temperature in bakeries and stores and sometimes they've sat there for a day without refrigeration.
So it's safe to keep apple pies and other pies out overnight.