Basically it works because bluetooth is a network like wifi. Each device participates in that network. It's not like two walkie-talkies where one can interfere with another so operators need to take turns. (It is on the low level, but more later) Instead, it's like a wifi-network where each device participates (takes turns).
Just like a wifi network, if one bluetooth device is sending a lot of data, then the other devices will need to wait. Your keyboard and mouse are less effected because they have short bursts of data. If you were to have, say a bluetooth speaker, a mouse, a keyboard, and a bluetooth hard drive all talking to the same computer, then your speaked and hard drive connections would go slower, and your mouse/keyboard would be less responsive.
Keep in mind that most bluetooth setups only contain 1-2 devices. It's not really a good choice for high data throughput, ormany device connections. It is however a good choice when just sending a tiny amount of data, or when just connecting to one thing. This limitation is why bluetooth hard drives, buletooth monitors, and bluetooh printers are not very popular, while their wifi counterparts are.
https://developer.bluetooth.org/TechnologyOverview/Pages/Topology.aspx Should help you understand.
Keep in mind this answer is high level and doesn't really look at protocols over bluetooth, or other "extensions" that work to solve these limitations.