Kwame M. Kilpatrick, who resigned as mayor of Detroit and pleaded guilty to obstruction of justice in 2008, was sentenced on Tuesday to as many as five years in prison for violating his probation. The sentence was harsher than expected, and elicited loud gasps in the courtroom.