I passed your species formula to a new variable in the function, and called it in the bg() function. Although for this to work I had to pass the list to a variable first, then use that variable in quotes when using the formula.
# function -------
ft <- function(dataset, values) {
test_formula <- as.formula(paste0("~Species %in%", values)) # create the formula
print(test_formula) # also printed it just to check
dataset %>%
flextable(theme_fun = flextable::theme_box) %>%
bg(bg = "#f0f0f0", i = test_formula) # pass it to the bg function
}
# Made a new variable for your list
test <- c("setosa", "versicolor")
# this does now -----------------
ft(df, "test")