Midnight gives us the clue and you might guess that this idiom means to stay up late.
But why midnight oil? It comes from the days before electricity. In fact, oil lamps have been around for thousands of years.
Click the link to see how Roman oil lamps were designed. A typical fuel of the time was olive oil.
A Selection of Roman Oil Lamps
While we're on the subject of Midnight Oil - here's a great song by the Australian band of the same name - this version features the lyrics (words), so you can read as you listen.
Just don't stay up burning the midnight oil or you'll regret it in the morning!