Foul smell in bathroom, ONLY when air conditioning is NOT blowing/running
To me it sounds like the vent from the bathroom to the outside must have moisture in it and growing something. I say this because many HVAC systems have a small percentage of fresh air added when they are running and this keeps the air moving out of the bathroom. When the System is off the smell wafts back into the room.
You may be able to use a spray disinfectant, Remove the cover, turn the fan on and direct the spray into the fan (not the motor) and spray for a few seconds,,, or minutes. put the cover back on and see if the smell is still there in a day or so.
I am guessing you have a fan since there are no windows and this has been code for decades.