Possible, yes. Easy, not so much.
However, it's easy to be a composite device with both keyboard and mouse at the same time (and joystick too). Just select it in Arduino from the Tools > USB Type menu.
If you really want to change device types at runtime, you're going to have a lot of programming work. All the existing code is designed to be only a fixed type. Of course, it is theoretically possible. You'll need to disconnect from the USB, which looks like a cable unplug to the PC. Then reconnect, and answer the descriptor requests with different data.
The key piece of code is probably the usb_descriptor_list array, at line 758 in usb_desc.c.
https://github.com/PaulStoffregen/cores/blob/master/teensy3/usb_desc.c#L758
When the PC requests a descriptor, the USB code reads this list to figure out what data to transmit. As you can see, it's declared as a const variable, and populated with fixed data. Perhaps if you change this to not be const, and re-write it with new info, that might do most of the work. Of course, you'll need to compose the 2 sets of descriptor data.
If you're crafty, you'll use different endpoints and just keep the existing code for doing both at the same time. If the descriptors don't mention the mouse, the PC won't access that endpoint, even if the first is implementing it. Likewise for keyboard.