I can't recall the timelines of the GPL release, but if it was before or after Valve started work, almost certainly paid ID tech to get the source code under a different licence (I think Valve confirmed at some point at least some of the engine code was still Quake, although they replaced a lot of it entirely).
The company/people that own the code are free to release it under as many licences as they like. This gets complicated with many contributors, as if one owner disagreed, all their contributions would have to be somehow removed, very hard for long lived code projects. Generally an employer will include in a contract that they get ownership for anything made by employees. They will likely also require that they have full ownership for any outside contributions before merging them.
For another example I believe MySQL does this (Enterprise Edition). A quick search for their contributing requirements says you must sign an “Oracle Contributor Agreement”, which will give Oracle ownership of the code to do as they please (for example merging into the GPL release, and their Enterprise Edition), they won't accept a patch under the GPL. MariaDB is I believe completely stuck with GPL, they would need permission from Oracle, and anyone that owns contributions since then to dual/re licence.