Why did tom Robinson have to go to court in mockingbird?

He was accused of molesting/raping mayella Ewell's because her father beats her because he's a drunk and she lied and said Robinson left the marks.