What is a stub on PCB and what is it used for? Stubs exist with PCB traces and also vias, why?
They're used for impedance matching and filtering.
The image from Wikipedia below shows different stripline features used to create various elements etched into a PCB with descriptions below.
Some simple planar filter structures are shown in the first column. The second column shows the open-wire equivalent circuit for these structures. The third column is a semi-lumped element approximation where the elements marked K or J are impedance or admittance transformers respectively. The fourth column shows a lumped-element approximation making the further assumption that the impedance transformers are λ/4 transformers.
(a) A short-circuit stub in parallel with the main line.
(b) An open-circuit stub in parallel with the main line.
(c) A short-circuit line coupled to the main line.
(d) Coupled short-circuited lines.
(e) Coupled open-circuited lines.
Stripline vias, (the little silver connections on the ends), represent a strap through the board making connection with the ground plane underneath
If you're familiar with transmission lines then you'll recognize the purpose for these elements. If you're not familiar, it's a scary yet fascinating topic I recommend learning more about. It's the weird stuff about electricity. Know your enemy.
There is a bit more explanation in a previous answer I gave on your previous question on via reflections.