Isn't this the exact thing that trademarks were invented to prevent? I don't really get how they are getting away with this.
That is what Grubhub claims they are doing. They aren't doing this to random third-parties - just restaurants that signed up with Grubhub's marketing service and agreed to allow them to do these things in their terms of service. Unfortunately, in this world of EULAs that are far too numerous to ever read and understand, most of the restaurants didn't realize what they were signing up for.
This behavior absolutely scummy, but the question of whether it is legal is more of a contract issue than a trademark one.