Greenhouse gases keep the planets warmer than they normally would. But, as with electrons trapping photons, I feel that thermodynamics is violated here. Is the violation allowed if energy is trapped for a short period?
Thermodynamics does not prevent the trapping of heat. Here are limitations that thermodynamics does impose on the energy balance of the Earth:
The temperature of the sun is comfortably above $3,000 K$ and the temperature of space is about $2.7 K$, so there is plenty of wiggle room, and we do, indeed, fall in between those two.
Greenhouse gases absorb more long wavelength light than short wavelength. The long wavelength is what we emit into space and the short wavelength is what we receive from the sun. By changing the ratio of what we absorb/emit, these gases can act as a sort of thermostat. This would not be possible if not for the abundant energy and high $T$ differential that our location in space gave us.