I’m going to make some assumptions here about Google’s algorithms based on my experience with using them as a consumer. (Note: I also develop GPS/mapping/routing software, but we do not use Google. We had to write our own, using a different API.).
As @Apparently_Im_The_Grumpy_One‘s link points out, there are many sources of data Google can use. But one of the big ones is the actual live data provided by phones that are actually driving the routes. My guess re: the traffic lights is that Google doesn’t know how long the lights are programmed for. Rather, it has a set of data that it can use to calculate an average time. It can also incorporate current traffic conditions and speed along these roads. It would be trivial to calculate adjustments to incorporate this historical data with current conditions to provide a fairly accurate estimate.
I have learned to just trust in my phone’s directions. I have a busy schedule, and all appointments are in my phone. It constantly monitors current traffic conditions and travel times so that it can tell me precisely when to leave. When an accident happens in front of me on my route, it redirects me before it affects me. Recently I was told to get off the highway even though there was no traffic. As the redirect sent me along some smaller, slower roads, I caught a glimpse of the highway up ahead and saw that it was a parking lot.
One thing to notice (if you’re interested) is what the traffic view looks like. Enable it on your phone and take a look at the color-coded traffic indicators. They are extremely accurate. As you drive the speed limit, you’ll see that you’re driving along green (no traffic) sections of your route. When things slow down due to traffic, you’ll see yourself driving on orange or red sections (depending on the severity of traffic). And when you see your car indicator on the map approaching yet another green section of road, it’s amazing to see how accurate it is when you’re suddenly out of the traffic and traveling normal speed again. This is possible because every car driving this road is a data point.