Possibilities
How high was the humidity? Did you provide both wet and dry areas so the beetle could self-regulate?
Might the beetle have been exposed to pesticides in soil or food?
How much ventilation was present?
Before it started twitching, did it show any signs of old age (scratched/worn body surface, leg loss, lethargy)?
What was it eating before the incident?