I mean, surely the other carriers around were already filled with planes. Did they leave extra space on other carriers for this situation? Did they evenly distribute the pilots among the other carriers?
The short answer is that they landed wherever there was room. Three American fleet carriers were sunk during the war; the Lexington at Coral Sea, the Yorktown at Midway, and the Hornet at Santa Cruz. The Yorktown is the best case of a carrier being left with large numbers of aircraft in the air after being hit.
The Yorktown scrambled every possible aircraft to engage the incoming attack wave from the Hiryu, including dive-bombers. Once the carrier was hit, the fighters and dive-bombers still aloft landed on the other American carriers or back at Midway island if they had the fuel.
Also interesting is what happened to on the Japanese side. When the Hiryu, the last of the four Japanese carriers was hit late in the day at Midway, large number of fighter aircraft were still airborne trying to engage the attackers. All four Japanese carriers were subsequently on fire and unusable, and the Japanese pilots simply ditched in the water next to friendly ships when they ran out of fuel.
Take a look at Shattered Sword, a book about Midway by Parshall + Tully, if you have time. There's lots of details about the technical side of carrier operations and how they worked, and is also very readable.