Basically there are points for 2 different disciplines. They add interest to the race for teams who might not have a GC (overall, yellow jersey) contender or have a GC contender and some other strong riders, if we take the Tour de France.
There are "sprinter points" for which you win the green jersey if you have the most, these are given for finishing positions at the end of a stage and also for positions crossing the line at set points in the race, called intermediate sprints (they are not always contested especially if there is a break away) this generally adds excitement to flatter stages as the GC contenders will have to stay up with the sprint teams in order to not lose too much time or get caught up in any crashes and the green jersey is a greatly desired jersey and certain teams will target it. Generally really strong fast explosive riders will win this points contest, think Sagan, Kittel, Degenkolb or Cavendish.
There are also "King of the Mountain" points for which you win the polka dot jersey, these are for climbers you win them for reaching the the top first, basically hills that are "classified" by the race organisers the harder the hill (height) the lower the classification and the more points, sometimes there are climbs that are not given any points. Climbs are classified as 4,3,2,1 or HC (1). This competition is for the lighter riders with good power output and pain threshold, often the GC riders are high in this competition as winning a GT often comes down to your climbing ability, think riders like Froome, Majka, Quintana.