On lucky nights when the medicine works, I can fall asleep after 1 a.m., but without it I can't sleep until around 4.

Literal

Luckily medicine [subject-が] work time 1-o'clock past [to-に] can-sleep [but-けど], medicine [object-を] drink-not-[conditional-と] 4-o'clock [approximately-ぐらい] [until-まで] can't-sleep.

寝れる is the ら抜き (ra-dropping) potential of 寝られる — increasingly standard in casual speech despite prescriptive objections. The sentence candidly describes insomnia with specific times, lending it an authentic, diary-like quality. 運よく ('luckily') at the start frames the medicine working as uncertain.