She couldn't sleep when she thought about what would happen if she failed.
Literal
She [topic-は] failed [when-とき] [of-の] [thing-こと] [object-を] thinking [conditional-と] could-not-sleep.
失敗したときのこと (what would happen if she failed / the time of failing) packages a hypothetical scenario into a noun phrase with こと. を考えると uses the conditional と — 'whenever she thought about it, (she couldn't sleep).' 眠れなかった is the potential negative of 眠る. The sentence captures anxiety about potential failure keeping someone awake at night.