We're in the process of making 4-day sweet gerkins and after the second day of soaking overnight the brine solution was foamy and has an unpleasant odor. Does this mean the pickles have gone bad?
It certainly sounds like they have gone bad yes. A bad smell is a dead give away. As with any such situation, a few cucumbers (or whatever you're unsure about the safety of eating) are not worth getting food poisoning over: if in doubt, throw it out.
Whenever you see froth in a bottle or jar that has not been shaken it indicates that some fermentation process is happening. If there is also a bad smell, you have bacteria doing the fermentation that is causing the froth.
Throw them away - lord only knows what bug is causing the problem, and it is not worth the trouble of finding out.
OTOH it may be time to sanitize the surfaces of your kitchen. People forget to wipe the undersides of cupboards, then put things like jars of pickle underneath the overhanging cupboard - under the false impression that because it looks clean there can't be anything stuck there which might fall into the jars.
I just threw out a bottle of blackcurrant cordial because it had "unnatural" froth in it ...