Hi there - I own a number of semiauto handguns and just recently purchased a rifle. I can tell you without question when you apply lube it is to ensure the parts move properly and cause minimal friction. I first began using lube after cleaning my gun well with a solvent (i.e. Ballistol, CLP, RemOil with Teflon MSDS, etc.) by placing a few drops in the spring at the rear of the gun (where there is movement of parts and metal to metal contact) as well as a small drop in the trigger area. I'd then stand the slide straight up, and drop some lub down the back of both rails and let it slide all the way down. As that is being done, I'd place a few drops on (and apply it all around) the barrel... Usually there is some oil left over that gathers on the front end of the slide after sliding all the way down, so I get a Q tip and apply that onto the inner walls and roof of the slide. Assemble back together and you are good to go. Nowadays I use Lucas Red 'n Tacky grease for the barrel, rails and the inner walls/roof of the slide since it stays in place and (in my opinion) makes racking the slide feel much smoother. Just take a small dab out of the tube with a Q Tip and apply. That tube looks like it's gonna last forever at the rate I am using it.
Rule of thumb, don't overdo it. Too much lube will eventually seep out of your gun, making the external portion very slippery. What's left internally has the potential to gum up important parts of your firearm as well.
I've chosen the less-is-more route which is why I went with grease instead for the high friction parts of the gun. I've owned 2 M&P Shield's (one with and one without safety) and can honestly tell the difference now between when I used lube-only as opposed to lube and grease. Much less wear on parts with high friction.