Yes, this should also work using the USBHost_t36 library.
Only Teensy 3.6 and 4.0 have USB host. They have only a single USB host port, so you'll need a USB hub to connect 2 USB MIDI devices.
USBHost_t36 supports the same API and callbacks as the serial MIDI library, so most of this code should work with only minor changes. Rather than MIDI_CREATE_INSTANCE(), with USBHost_t36 to create 2 or more instances of the MIDIDevice class, and of course an instance of USBHub. The library has a couple MIDI examples showing how to receive input messages with the callbacks, and how to receive arbitrary messages (without figuring out which message they are) when your only goal is to forward them to a different MIDI port like the serial MIDI library.
Regarding Trinket, you should ask Adafruit. But even it if can work, since those boards have only a single USB port, getting it working would probably be quite a challenge. While you could theoretically swap cables for each upload, as a practical matter you'd probably need some other non-USB way to program and test. Teensy 3.6 and 4.0 have 2 USB ports, so uploading code and everything else works normally on the main port while you use the 2nd port for USB host.
Only one Teensy 3.6 or 4.0 should be needed, plus a cable to USB host pins. You can connect 2 or more USB MIDI keyboards or other USB MIDI devices by using USB hubs. USBHost_t36 has very good hub support.