A mortgage is simply a loan backed by a property (and, because it's both very large and very common, covered by some specific laws). As such, the bank isn't an "investor" in your house; it simply is lending you money with the property as collateral. So, it doesn't get any share of the profit.
As long as you sell the house on your own, for more than you owe, most of the time in the US you will get about 92-94% of the sale price back, minus whatever you owe on the house. The 6-8% you don't get will go to the realtors as commission (unless you sell by owner and don't sell to someone with a buyer's agent), and to pay some of the costs of the sale (how much of those you pay depends on the deal you make with the buyer, but it's common to pay some of them in some areas). You also will owe taxes (potentially). You then pay the bank back from that amount.
As such, in your example, let's say Bob owes $50k on his house, and sells it with a realtor for $150k. He gets $150k-0.06*150k = 141k after commission.
He then hands the bank a check for the current payoff of the loan: that amount is usually slightly higher than the remaining principal, because you owe the interest that's accrued between [last payment you made] and [day of sale]. Let's say this is a 6% loan, which works out to around 0.5% per month, and it's been half a month since his last payment, so he owes another 0.25%, or another $125. Some mortgages also may have prepayment penalties (check your note). In this case there isn't a penalty, so the bank gets $50,125 from the sale. Usually, the bank would get that immediately at closing - ie, he doesn't get the full $141k or $150k and then write a check, instead the title/closing company gets that amount, and gives the $9k to the realtors, the $50,125 to the bank, and the remaining $90,875 to him.
Don't forget he may also owe income taxes, and sometimes other local taxes, on the profit on the sale. In this case the IRS wouldn't get anything (as it's under $250k), assuming it's a primary residence, but keep that in mind.
Also - in the case of a foreclosure, the bank will get some extra money to pay for the costs it incurred in foreclosing on and selling the house.