wp_insert_post() does not support variable

There is no difference in PHP between a string and a variable set to a string, so the problem is elsewhere.

Most likely it is with passing the slug argument as mentioned in the codex for wp_insert_term: https://codex.wordpress.org/Function_Reference/wp_insert_term :

If ‘slug’ argument exists then the slug will be checked to see if it is
not a valid term. If that check succeeds (it is not a valid term),
then it is added and the term id is given. If it fails, then a check
is made to whether the taxonomy is hierarchical and the parent
argument is not empty. If the second check succeeds, the term will be
inserted and the term id will be given. If the slug argument is empty,
then it will be calculated from the term name.

You could try understanding that – or just try removing the slug argument and allowing it to be generated automatically from the string passed.