This is very dependent on company culture. However, there are some general things to consider. There are mainly two reasons why calling code garbage might be considered unprofessional:
- It does - by itself - not provide insight as to what is bad or how to improve the situation, it just gives that code a (low) value, while typically you want to look at its advantages and disadvantages rather than consider it generally bad or good
- it may be offensive to a colleague, i.e. the person who wrote that code
As for 1), that can be alleviated by providing concrete details as to what you think is bad and how to fix it. Typically, there are reasons why things are as they are and it's not that someone just wanted to write garbage. The code might have been perfect for the job it was intended for when it was written, but the context changed.
As for 2), if the code you refer to is a recent commit from a particular person, that person might feel offended. Especially if he had reasons to write something objectively bad, like time constraints, that you don't take into account. And often what is garbage to you is perfect for someone else, calling it garbage just brings emotions into what otherwise could have been a well founded objective discussion. On the other end of the spectrum - if you take over an old large codebase that no one in the current team already considers "his code", it's pretty impersonal to call that big pile of probably convoluted code garbage (still doesn't address 1. though and you better back it up).
Another issue is how you deliver any line containing expletives. The more emotionally loaded (and accusing) the worse, the more light-hearted, perhaps ironically aimed at yourself the more acceptable.
So, if you are unsure, never call something garbage. If you want to test the waters, start using such valuing language for code that no one feels attached to (or your own code) and back yourself up with some details as to what you don't like.
Whether people react offended and consider you (un)professional solely based on the words you use depends on the company culture. However, universally people will judge you based on how you use your words. If you just call stuff garbage without arguing your point of view, without accepting another developers argument as to why the code is fine as it is, people will think you are unreasonable and judgemental. And thus unprofessional. Especially if you explicitly or implicitly blame your co-workers for what you consider bad code.
This is true no matter whether you use expletives or not, i.e. saying "this code is just bad", without any further comments, is unprofessional as well, but the more emotionally loaded words you use (and the more emotionally loaded you present them), the worse this gets.
That being said, if you use expletive words in a reasonable fashion without directing them at your co-workers but rather as a means to give weight to your impressions or vent off some frustration, it can be totally fine. I've worked in an environment where the tone was very direct, playful and the sentences often full of expletives. But typically any such expletive was directed at some technical problems, the way some frameworks behaved unpredictably or even at one's own code ("Look at the garbage I did there, it's incredible that I wrote that stuff!"). On the other hand, I've rarely seen a team working so professionally - respecting each other, always looking how to fix the problem and not how to distribute the blame.
TLDR: using expletives to describe code isn't necessarily unprofessional in itself. In some cultural contexts, however, any use of expletives is considered unprofessional/offensive. It is your job to figure out whether this is the case in your environment before using them, not doing this first is unprofessional.
If (another person's) code is absolutely valued, using expletives or not, without a) giving details and b) without separating that criticism from the person and c) without knowing that the other person can separate criticism of their code and criticism of themselves, this is unprofessional as well.
In your current company, people are obviously not accustomed to any swearing / expletives and consider it bad behaviour - so don't do it.