How does it work when actual source license is GPL?

Copyright and trademark are two entirely different things.

Copyright protects the right of authors to decide how their work is used -- it applies to the content, e.g. the code.

Trademark protects the right of consumers to not be misled by fakes or frauds -- it applies to the names and identifiers that people apply to products and services, e.g the brand name.

Open source copyright licenses allow you to use the source code, but they typically do not grant any trademark rights.

https://en.wikipedia.org/wiki/Debian%E2%80%93Mozilla_tradema...|

It is Mozilla public license, not GPL, but the story is the same.

Or look at CentOS (before it was acquired by RedHat)

The author is happy for people to fork etc, you just can't call it "notepad++" since that's trademarked