According to the official select2 documentation this issue occurs because Bootstrap modals tend to steal focus from other elements outside of the modal.
By default Select2 attaches the dropdown menu to the element and it is considered "outside of the modal".
Instead attach the dropdown to the modal itself with the dropdownParent setting:
$('#myModal').select2({
dropdownParent: $('#myModal')
});
See reference: https://select2.org/troubleshooting/common-problems