Yes it's safe to leave an apple pie out overnight and it will remain safe to eat.
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.
But for years my Grandma, Mom and even myself have kept apple pies as well as pumpkin pies etc out overnight without any issues.
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.