Non-Markovian epidemic dynamics on networks