The points are awarded according to the placement at the finish line of every single stage. There are intermediate sprints as well but the number of points awarded there (4 points for the fastest rider) does not make much difference in comparison to the stage wins (25 points for the fastest rider). With the high number of summit finishes at La Vuelta, the results often correlate with the general classification.
https://www.instagram.com/p/B2XCVzkINRl/
In 2012, for example, John Degenkolb won five sprint stages but finished fourth in the points classification. Alejandro Valverde scored the points needed in the mountains and beat him by 50 in the end. Coincidently, Valverde, alongside Seán Kelly and Laurent Jalabert, has 4 titles to his name. Will Roglič threaten this record in the future? We shall see.
1 Primož Roglič (Team Jumbo–Visma) – 155
2 Tadej Pogačar (UAE Team Emirates) – 136
3 Sam Bennett (Bora–Hansgrohe) – 134
4 Alejandro Valverde (Movistar Team) – 132
5 Nairo Quintana (Movistar Team) – 100
6 Miguel Ángel López (Astana) – 76
7 Philippe Gilbert (Deceuninck–Quick-Step) – 73
8 Dylan Teuns (Bahrain–Merida) – 69
9 Tosh Van der Sande (Lotto–Soudal) – 63
10 Sergio Higuita (EF Education First) – 62