When is it acceptable to write a bad letter of recommendation?
Never write a bad recommendation letter. If you can't say anything nice, say nothing at all (and tell the student you can't write the letter).

As for warning other. Leaving aside the law for a moment, the only time I can see it being appropriate to warn others about a student is if you believed them to be dangerous. Examples of this might be a history of sexual harassment/assault, bullying or other abusive behaviour.