Going into TPE on a 5 hour layover? In my opinion, it is doable but not recommended.
Getting from gate thru customs - 30 to 45 minutes.
Buy ticket and wait for bus -15 to 20 minutes.
Bus ride into Taipei - 45 minutes to 1.5 hour depending on traffic.
Even in best case scenario it will take 1.5 hour one way. Multiply that by 2 and you have only 2 hours left to enjoy Taipei. If your bus gets stuck in traffic (and the odds of that happening is very high), you might find yourself not able to get back to the airport in time for your outbound flight.