For a start, you could type in "copyright" in Wikipedia, read the article, as well as the relevant articles linked to from it. That is a LOT of reading though, basically because this is a very complicated subject.
The game is freeware, so no profits, it's only a cameo, so something very small all people may not even notice, and you could make it satire, to which copyright doesn't apply, although that's what I understand from it; I'm not a lawyer.
More importantly, do the copyright holders (id Software) care, or care enough to sue some person/fan making a freeware game?
I doubt it, and as long as you're not doing anything in bad taste they won't have a reason either.
(Well, of course sometimes fan games are shut down because the IP's creators are afraid the inferior material could hurt their IP.)
Id didn't mind the Masters of Doom Flash cartoon either, so that's cool.