Sounds like the law worked fine to me.
Exactly.
The foreigner in question could have easily avoided any of that by carrying the documents he is legally bound to have on his person.
Follow the law, why is this too much to ask of foreigners?