"Lock in" is used to mean secure with a lock.
He was locked in prison.
Because I couldn't find my keys, I was locked in my house.
I locked my jewellery in my safe.
Lock in used metaphorically means making secure or certain.
“The biggest lesson we learned from the global financial crisis was to not abandon stocks because that’s how we lock in* losses,” Hooper said. “Maintain disciplined, long-term asset allocations.”
The sense here is that losses are made certain. Normally one would talk about locking in – something one has.
My shares were already up 30%, so I sold them to lock in the gains.
The profit I have made on paper is made certain by selling the shares.
By extension, it can also be used to mean make a loss certain. And that is the sense above*: once the shares are sold at a loss, it is a certain loss.
The language is no doubt influenced by gambling language. Poker players use the word "lock" to mean a poker hand that is unbeatable; no matter what cards come, or what the opponents hold, the hand is certain to win.
The term "lock in" can also refer to a private gathering in a pub after hours. In that situation after public opening hours have ended, the landlord locks the doors, making it now a private gathering, usually so the drinking may continue.