Why do I get compile errors if I comment out an include?

The LDF will resolve dependencies to the things it finds an #include for – that’s documented here and here.

All build options are documented. Under the hood, PlatformIO uses SCons (currently 4.3), which is documented. Some more technical details are here.