Photovoltaic cells vs. Second law of thermodynamics? Question: How do photovoltaic cells actually work?
Here is the standard explanation:

*

*Photovoltaic cells comprise of an N-P silicon junction.  The terminals are in electrical contact with the N and P doped silicon

*At rest, thermal movement of the electrons and holes produces a Depletion Zone.  There is an electric field across the depletion zone, pointing from the positively-charged N-doped silicon to the negatively charged P-doped silicon.

*When photons hit the depletion zone, sometimes a photo electron is produced.  The liberated electron and hole are attracted to opposite ends of the depletion zone, producing the net charge difference across the PV cell.

That explanation sounds satisfactory, but it can't be the complete story, because it would violate the second law of thermodynamics.  Imagine the following thought experiment:

*

*I have a blackbody in a perfectly reflective and thermally insulated container.

*I have a solar panel pointing at the black body.  The wires come out through the container.

*I wait until there is thermal equilibrium, and then I suddenly flick a switch to connect the circuit, and let the electricity from the PV cell do useful electrical work.

Question: Would the PV cell generate electricity in this case?
No part of the first paragraph would preclude the PV cell from generating electricity in this scenario.  But I contend that this would violate the second law of thermodynamics.  The PV cell would be converting the blackbody radiation (heat) entirely into useful electrical work, without the need to dump waste heat into a heat sink.
Basically, this would be a heat engine with a heat reservoir, but no need for a heat sink!!
 A: The solar photosphere has a temperature of ~6000K. In theory, a body on Earth can be brought to equilibrium with that using a suitable optical system. Assuming that as a heat source, and assuming a heat sink temperature of 300K, the efficiency of a perfect solar-driven heat engine would be $1-300K/6000K=95\%$.
That's not really the limit, as the solar spectrum isn't a perfect blackbody, and the radiation is collimated at Earth, but I'll leave the consequences of this as an exercise for the reader ツ
Practical solar furnaces can achieve 3000K, so even there, the thermodynamic limit is 90%. A solar cell has much lower efficiency, so there's no thermodynamic issue. We don't normally think of solar cells as heat engines: they take their energy from photons well beyond the thermal spectrum at their operating temperature.
The flaw in your analysis is that you're assuming a solar cell in thermal equilibrium with the radiation illuminating it. This is far from reality, since sunlight has far less entropy than thermal radiation with the same energy flux.
A: The thought experiment assume equilibrium between the radiation and the photovoltaic cell, which is not the case in normal conditions: the cell is assumed to be collected to a sink that quickly removes the generated electrons and holes. If this were not the case, the electron and holes would remain in the cell, occasionally recombining and producing photons. Thus, the equilibrium with the radiation would be established by emitting as many photons as is absorbed by the cell.
The proposed thought experiment can be viewed as a photovoltaic equivalent of Maxwell's demon: it appears as a paradox, because there is a demon that allows the flow of energy in one direction (creation of electron-hole pairs), but not in the other. As all the demons of this kind, it is resolved by going beyond a simplified model of the phenomenon (nicely summarized in the first part of the OP.)
A: I see two problems in your thought experiment:
First, the equilibrium is not going to happen even if I go along with the (non-realistic) tacit assumption that the material will not undergo phase changes when finding thermal equilibrium. In an open clamp situation (switch is open in your experiment) the PV cell absorbs photons in UV-VIS range. The generated excited electrons have a finite lifetime before recombining and dissipating the energy as heat. The heat will be radiated as lower energy infrared photons. This is not an equilibrium; it is a pseudo-steady state. As the PV material heats up due to this process in the thought experiment, hoping to reach a proper equilibrium, the Fermi level will rise, until eventually it exceeds the conduction band and then the photovoltaic effect will no longer work (no more junction to have a voltage drop over). Equilibrating at lower temperature will also not work, since we require the high energy photons from the black body in order to be able to excite electrons over the band gap, otherwise there will be no charge carriers available to do work in the second part of the thought experiment.
Second, if you really want to ignore the above, the second part of the thought experiment is not going to work either. As soon as you flip the switch, the wires and whatever is connected to it become part of the system. So, as soon as you flip the switch, you break the equilibrium, entropy will change, and no violation will occur.
If you really want to know how these things work I can advise Solar Cells by Green, and Chalcogenide Photovoltaics by Scheer and Schock.
A: Let's say a big solar cell surrounds the sun. Now it's clear that the temperature of the radiation hitting the cell is 6000 degrees, temperature of the sun.
Now photons create free electrons and free holes inside the cell. The energy of the photons gets used in this process that requires energy.
Now we know that somewhere electrons and holes must be combining, which is a process in which energy is released, so this must be the process that generates electric energy.
Hmm, metal is a n-type conductor, right?
So, where metal is connected to the p-type semiconductor, there electrons and holes are combining generating electric energy, if the junction is cool.
When the temperature of said junction is 6000 degrees, then in the junction free electrons and free holes are generated at the same rate at which electrons and holes are combining, so we get no electrical energy out.
