There is a playing reason as well, which is easy to appreciate once you have needed it.
The key block sets the space around the outermost keys. Without it — with the case wall coming straight down beside the lowest key — your hand hits the side of the instrument when you play the bottom of the keyboard with any force or with the hand angled. On a piece that lives down there, that matters.
The height of the blocks is also part of the geometry. They are typically level with or slightly above the white keys, so they do not obstruct the hand travelling along the keyboard, and on many instruments the upper surface is where the fallboard rests when closed.
So: structural first, ergonomic second, and it is doing both jobs at once.