How can a nonspontaneous reaction occur?
When you add energy from somewhere, let's say a battery, you are creating a greater amount of entropy there (in the battery or whatever). That's all there is to it. The Second Law is not violated.
The electrolysis process is not non-spontaneous. Yes, it would not occur in the absence of the battery. But the fact that it does occur with the battery there must tell you that overall it is spontaneous. The fact that you are coupling a strongly spontaneous reaction (discharge of the batter) with a non-spontaneous reaction (the electrolysis) means that overall, the electrolytic process is spontaneous.
It's incorrect to treat the electrolysis as if it occurs without the battery.