You're running into the difference between what your eyes see and what the algorithm actually optimizes for. Everyone above has nailed the core point - it's all about minimizing *time*, not distance - but there's a practical layer worth understanding: Google Maps is constantly recalibrating based on when you're actually going to be driving.
So it's not just "highway X has a 65 mph speed limit." The system knows that at 3 PM on a Tuesday, that highway gets clogged near the downtown exit, dropping to 15 mph for 2 miles. Meanwhile your longer scenic route might be 8 miles instead of 6, but it flows at steady 50 mph the whole way. The math works out: 8 miles at 50 mph beats 6 miles when 2 of those miles crawl at 15 mph. Add in things like traffic light patterns on surface streets, turn restrictions, and road geometry (tight curves slow you down), and suddenly a route that looks "longer" on the map is genuinely faster in real driving conditions.
The tricky part is that this prediction gets better the more data Google collects, but it can still whiff - especially if there's an accident you hit right as you're driving, or if traffic patterns shifted since their last update. That's why sometimes you'll second-guess the app and it turns out right anyway, or why you occasionally get the sense it sent you the wrong way. The algorithm is making its best guess based on historical patterns, not actually seeing the road right now.