Static and dynamic SOQL need appropriately typed bindings. For this to work you need the "listOfIds" to be one of:
or even: List<Account> (where the Account instances include at least the Id field)
SOQL in Apex does not, by default, honor profile permissions. To do so, add WITH SECURITY_ENFORCED. As the documentation says:
Apex generally runs in system context; that is, the current user's permissions, field-level security, and sharing rules aren’t taken into account during code execution. Although performing field- and object-level security checks ...