Dimensionality-induced insulator-metal crossover in layered nickelates Lan+1NinO2n+2 (n = 2, 3, and ∞)