Three ways, mostly. Some are stumbled on by players experimenting with inputs. Others come from inside the industry — developers and testers who let something slip, or who talk to a gaming magazine, which was the main channel in the print era. And increasingly, players find them by inspecting the game's own files, where leftover debug functions and unused content sit in plain text.