Indeed it's as compatible as I could make it.
But some features, like the DAC and 5V input tolerance on the digital I/O pins simply don't exist in the newer chips.
Several features which do exist, like I2S digital audio and CAN bus, don't share the same pins. Priority was given to the more basic pinout features (pins 0-13 are digital, pins 14-23 have analog input, SPI on pins 10-13, Serial1 on pins 0-1, I2C at pins 18-19, etc). More advanced features like I2S and CAN which do exist are at different pins, because there was no way to keep the more basic stuff compatible and also get these at the same locations. That's why we made a Rev D audio shield with exactly the same hardware as Rev C, but with the signals routed to their locations on Teensy 4.x.
So for a lot of applications which use the Arduino functions and libraries for the basic I/O and peripherals, Teensy 4.0 is a drop-in replacement. But for use of more peripherals or code that directly uses the hardware registers, switching boards isn't so simple.