Quite simple really, it's an offence to walk about in a public place baulik naked. Breach of the Peace, if memory serves me correct.
It aint the Polis's fault, they couldn't give a flyin' feck. Trust me, way better things to do.
Every-time a member of the Public makes a complaint, the Polis will act (exactly what happened here.) Don't act and you leave yourself open to a complaint and potential disciplinary action.
So he got stopped in Dunfermline, perfect. Means he goes to Saughton rather than Perth prison. When he gets released, he's in L&B Polis area, a wee bit nearer home and won't bother Fife Polis again.
I reckon that was a tactical arrest, but then, maybe I'm just guessing

Mur