Oh, they absolutely have a right to claim a profit on the transaction, they have a right to profit as much as they possibly can on it. And, if you BYO, they have a right to try to recoup the money they lost by you not buying your wine from them.
Note also that the retail cost of the wine might be less than the price the restaurant pays, so their markup may be less than what we're assuming. On the other hand, it might be the exact opposite. It depends largely on the wine and the state's laws.
My feeling is, if you feel the markup applied is offset by the value to you of the service, setting, etc, then by all means order that bottle of wine. If it doesn't, don't.
Other things to keep in mind: the restaurant probably has to add ~10-20% of the cost of the wine as markup to cover bottles being corked, getting broken, or getting stolen. With wines by the glass, they have to be able to cover those bottles where they only sell one glass before having to dump the bottle.
So it is, as michael said, a complex calculation, with a lot of factors, and it was very simplistic for me to reduce it entirely to profit motive.
But just keep in mind this quote from Bill Buford's article about Gordon Ramsey: "The [food] prices--the best value in New York--had been deliberately set low, Ramsay told me, to encourage people to spend more on wine, an upmarket restaurant's greatest potential profit (no overhead, no spoiled ingredients)."