It's a good question!
As you mentioned, "선생님" means literally "a teach", but in a converstation w/ an old person,
people usually uses it as "you" to show respect him/her.
It could be used to call a stranger older than mid-age (50's or more) , like a merchant.
This is one of the most formal styles to call the elders, which can give an impression that you are a very courteous person.
And sometimes, people calls the veterans in their field as "선생님",
even they don't participate any teaching program.
a young actor/actress calls a veteran actor/actress "선생님" to show his/her respect.
"선생님" is a very formal calling to the elders, as well as, a veteran.