Hi Gilbert, welcome to the Community!
Please have a look at this guide on How to block the merge of Merge Requests when SonarQube Quality Gate is failed, with GitLab.
I am sure you will find there how to achieve what you are looking for. In any case I would suggest for you to work with failing Pull Request pipelines instead of failing the branch pipelines, as this may impede your developers from testing their code.
Best regards,
Daniel