Going back to antiquity, things always evolve the way they do because over the centuries people find it the most practical and popular method. Elucidating "why" is a murky question at best.
The keyboard first evolved to play arrays of church bells. The "keys" were large heavy foot- and hand-operated levers that triggered ropes that rang bells, and required the performer to throw their body weight onto each lever. It was not possible to damp each bell, or to restrict the length of the sounding of each note; each bell continued to ring out after it was struck. The bells would be arranged and tuned to play very simple melodies in modes and scales with few notes, where the ringing overtones of the bells would not clash with each other too much. Chromaticism was avoided; the overtone series of the lowest bell and the root pitch produced the purest scale with the least clashing overtones.
The first primitive pipe organs were invented in 228 BC (before the use of keyboards controlling bells), and they began to include keyboards that could be operated by the fingers, which only had to be strong enough to open and close the valves of compressed air going to the pipes (the compressed air was supplied by someone other than the keyboardist who was pumping an air bellows.) This means that the keyboardist could control not only the starting of each note, but the point at which it stopped as well.
It's fair to say that the first keyboards on the first organs, in Western civilization, which were certainly rare, expensive and sophisticated mechanical devices for their day, were built to accompany singers who were singing Gregorian chants or melodies of similar structure. These melodies adhere to a certain very strict "mode" or scale and do not involve chromaticism or modulation. They also do not involve harmony or chords at all. So the pipes would be built and tuned to play only the notes needed for this kind of very simple music that was deliberately restricted in its scope. (At the start, extra pipes tuned to chromatic pitches would expand the cost and reduce the reliability of such an expensive and delicate instrument, so doubtless they were avoided.) Regardless of the master tuning-fork pitch to which they were all tuned, with the simple Gregorian chants, the starting note would be "A" and the most common mode would be the A-minor scale, so that gives us the "white" notes.
As Western music composition and theory gradually became more sophisticated, and melodies were composed which were more elaborate, extra pitches would be required, not only on the organ keyboard, but on other musical instruments with fingerings, such as woodwinds, and stringed instruments with frets. I would imagine that successive generations of pipe organs were built which gradually incorporated additional chromatic pitches one by one. I doubt that the modern keyboard layout of 12 pitches to the octave appeared overnight. But the point is that as additional pitches were added that were between the established 7 pitches of the natural minor scale, the logical place to put the extra keys seems to have been physically locating each new key between the two keys representing the pitches tuned immediately below and above the newly introduced pitch. Placing them higher in elevation and further back, and using a smaller key, seemed to work well for keyboardists concentrating on playing the "white" keys. It just slowly evolved that way.
It is worth noting that keyboardists did not use all ten fingers in playing the keyboard until comparatively recently! The innovation of using the thumbs was popularized by none other than J. S. Bach (1685-1750) and by that time keyboards had already standardized on the physical size and layout of keys that we see on pianos today. Before Bach, most keyboardists used only the first three fingers of each hand: six fingers, not all ten. Therefore it seems that what has come to be the standard keyboard layout that we see today must have evolved with playing with only those six fingers in mind. But Bach found that he could play scales, chord progressions, and all musical passages with all ten fingers on the keyboard he already had, and that this was a great advantage.
It is worth noting that in the Renaissance and Baroque periods there were certainly keyboards for pipe organs and for percussion instruments like the harpsichord and clavicord that had more than 12 keys and pitches per octave -- in some cases far more. There are still pipe organs being built today which are replicas of Baroque instruments and that have a somewhat standard (for the era) layout of 15 pitches and keys per octave, used for playing Baroque music in meantone tuning. It sounds crazy to us today, but they exist.
15-key "split key" organ keyboard for playing in Baroque meantone tuning. This is from a working organ in Boston, Massachusetts, USA