Issue with matrix keypad vs pull up buttons (in the code)

Perhaps set gotKey = false before if (key) {makes it true}
unless you do that elsewhere?

Otherwise once true always true.

Holy cow the delays you use!

BTW, you can run a button matrix with 1 diode per button on INPUT_PULLUP pin power alone.