In America, the reason is basically “religion”. There are architectural standards which designers refer to for guidance, and the dude who did the architectural standard for restrooms was super hardcore religious. His standard called for big gaps in all the seams, to prevent people from masturbating in the stalls. Basically, he wanted people to be able to peek into stalls, as a sort of modesty check. And eventually, it just became accepted as normal, even though everyone (including Americans who were born and raised with them as the standard) hates the huge gaps.
In modern day, they’re mostly done to deter drug use. I guess the reasoning is similar, with the large gaps intended to allow people to peek into the stalls and see if someone is doing drugs.
The “AI checkers” that schools/unis use has found a strong correlation between neurodiversity and sounding like AI. Basically, AI sounds autistic, so autistic people get flagged as AI.