First, one would have to define the number of buttons which would have to be read. Often, the Teensy 2.0++ or the Teensy 3.5/6 have enough pins to read many buttons directly, without matrix, depending on the number of pins which you‘ll perhaps need afterwards for other functionalities. If you really must go for a matrix, you trade less used pins for more complex code. So, for 20 buttons, you would not longer need 20 pins, but only 9 (4 cols x 5 rows).
A matrix consists of rows and columns and the buttons are wired in a way that each button, when pressed, connects exactly one column wire with one row wire. Now comes the code side: In a loop, the column wires will be driven high for a short interval (i.e. 20ms) and then again low, one after the other, in a cyclic way. Each time, one column wire is driven high, all row pins will be read to see if one of the buttons in this columns is pressed. From the number of the actual high column and the row pin which is driven high, the code will know which button is pressed and can invoke any action which is intended to happen whet his specific button is pressed.
Basically, it‘s relatively simple - no black magic! In reality, after a button press is detected, your code would first check if that button was already pressed during the last column cycle, to prevent repeated triggering. That‘s all.