You have a misunderstanding on how tags work. Please read though this excellent answer for full explanation, but here's a snippet from it:
It is important to understand that tags have no direct relationship with branches - they only ever identify a commit.
So, when a tag is created, even for a branch, it is not really created for that branch, but as a reference to the latest commit in that branch. That is also why GitLab documentation mentions these:
CI_COMMIT_TAG - The commit tag name. Available only in pipelines for tags. CI_COMMIT_BRANCH - The commit branch name. Available in branch pipelines, including pipelines for the default branch. Not available in merge request pipelines or tag pipelines.
So, your pipeline will fail because those two variables can't coexist, so your question becomes a bit problematic.
Maybe you wan't to identify if the commit of the tag is available in the main branch? In theory something like this could help: Git: How to find out on which branch a tag is?, but you cannot run arbitrary git operations in a GitLab rules:if clause.
Not ideal, but your best option is probably to do the check in a script and fail the job in case the tag was not created for a commit that exists in the main branch:
script: - | if [[ -z $(git branch --list $CI_DEFAULT_BRANCH --contains tags/$CI_COMMIT_TAG) ]]; then exit 1 fi