Simply put, the glass in the analogy traps the sun’s heat inside the greenhouse, warming the interior and not letting the heat escape, just like greenhouse gases (CO2, methane, etc) trap the sun’s heat in the atmosphere, warming the planet and preventing heat from escaping back into space.