For what is worth, I found this question in 2025. UsingUsing QGIS version 3.34, I used the function eval()eval() to "convert" the variable to a string so it can be processed as a query.
In my case I wanted to be able to change the field name used in a query for a rule based renderer, because not always the structure of the data that I was using was the same.
So for a query like:
TIPO in ('22400000','22440000')
TIPO in ('22400000','22440000') where I could have the field named LAYER or CODICE, I defined a project variable:
@project_layer_field
@project_layer_field set as TIPO, and used in the filter
eval( @project_layer_field ) in ('22400000','22440000')
eval( @project_layer_field ) in ('22400000','22440000') and it worked as expected.