Merchants only sell 3 of a type of weapon. If you sell the same type of weapon (and the stock is already under 3) it'll go up by 1 and one of the same item will be added to the bottom of the inventory list.
So you can buy 3 daggers and he'll be out of stock. Sell 3 daggers back to him and you can buy the 3 back and the 3 that were just added to the bottom of the list for a total of 6 and it can be repeated.
The reason for this is each item is not nessecarily the same when you sell them back as their shop inventory. They maintain their own durability, and possibly attributes such as sharpening or foritication, or magical elements so it is not a straight forward comparison