The weird casting is required because in this case get_target() returns an object of type lv_keyboard, and not lv_btnmatrix.
Although lv_keyboard inherits from lv_btnmatrix, it was decided that every child class should reimplement all its parent methods (except from lv_obj methods)
So, I would say this is a bug in LVGL API where lv_btnmatrix methods are not reimplemented in lv_keyboard.
@embeddedt / @kisvegabor - Do you agree?