Your theory is mostly right

. Usually the chosen bacteria have special resistence to the stomach environment also, which insures that some of them make it through. Lactic bacteria enter in this category.
As to what they actually do, there are real, proven benefits, but also a significant amount of woo science on that.
Good bacteria naturally inhabit the bowels. They help with digestion and some will produce vitamin K, necessary for efficient coagulation, for you. The other purpose is to inhabit, occupy, your bowels so that pathogenic bacteria (those that give you diarrhea) stay away.
So for example there are benefits in taking those bacteria if you are taking antibiotics, since some antibiotics tend to kill bowel bacteria, making you vulnerable to diarrhea-causing ones. However, yogurt rarely contains enough for that purpose; concentrated pill-form supplements are more efficient (those need to be kept in a cool place and wont keep good for long). Another thing is that the
intestinal flora, the bowel bacteria, contains much more variety of bacterial strains than what is proposed in supplements. So they can help, but they are no panacea.
Some claim that they
help the immune system, which is a very broad statement, probably based on studies linking the intestinal flora of infants with auto-immune diseases. Personnally I would be cautious about these claims.
the Kemist