Say the current price of a stock is 99.9
Lets assume here that there is an offer for the stock posted on the book at $99.90.
investor A places a buy order with a limit of 101, and
investor B places a sell order with a limit of 99
This is potentially creating what is called a 'crossed market' (where the bid exceeds the offer and vice versa).
How this is handled depends on the time and to which exchange the orders are transmitted.
Now, assuming there is already an offer on the book at 99 (the "current price" the OP suggested), the process works like this:
What price will the stock sell at?
If the order is being transmitted to the exchange where the 99.0 offer is posted, the order will immediately interact with that posted price, trading at 99 until the either the quantity on the book is removed or the quantity of the order is removed.
If the order were a very large order, then it would continue to trade against the next price level up (e.g. 100.99, 100.98.. and so on).
If the situation were reversed, and a 101 bid had been posted, and someone wanted to sell at 99, they will get filled at 101 first, until that quantity had been removed, working down to 99. Effectively the limit order is being treated like a market order, with the exception that it only applies if the price is within the limit order's specified range.
However, the order protection rules applies which prevents exchanges from posting bids that match offers posted on other exchanges ("locking the market") or posting bids that exceed the price on other markets ("crossing the market").
If the order was sent to an exchange that wasn't the one holding the 99 offer, then that exchange will either 'hide' the order (so it is not displayed on the NBBO), route the order to the exchange at the NBBO, or reject the order. These behaviors can usually be controlled on the order level. Alternatively the exchange could just ignore the rule and go out and lock the market... but suffer the consequences if its behavior is being reviewed by the regulator at the time.
In general, most exchanges pass on the burden of handling the locked and crossed markets onto its members, particularly its market makers. They are then fined if they engage in a "pattern or practice" of locking or crossing markets. Some exchanges make this process easier by automatically exhibiting the behaviors described above unless the broker overrides them (and takes responsibility).
Note: the order protection rules apply only during normal trading hours, not in the after-hours or pre-open markets.