Legal or not, this is not the way a human should treat another. I suppose this is what happens when the one and only goal is profit - Amazon delivery drivers peeing in bottles in their trucks comes to mind ...
UPS drivers pee in bottles while out delivering, too.
In another life I worked facilities at a UPS distribution center and my team would have to pick up those bottles :-/
When yah gotta go, yah gotta go.
I have friends who have done this when they were stuck in traffic.
I imagine that when UPS drivers do their deliveries like in the suburbs, there might not be public restrooms nearby.
In reality, like always, it's a mix of both - meeting delivery deadlines, and meeting nature-call deadlines.
In the context of an employer monitoring employee toilet breaks, this is perversely amusing.