Removing a centroid leaves components with at most nodes. This guarantees balanced splits, which means recursive depth is . Each level of recursion halves the problem size. Every path in the tree passes through some centroid in the decomposition. This is the core idea: process paths through centroids, not all paths directly.
You count paths at each centroid, avoiding brute force. These properties turn brute force into divide-and-conquer. The balance is what makes it work.
Space complexity is for the data structures used.