Make sure you have trinity to set to keep the keys in the backpack. Make sure you have it set to collect them in the checkboxes of the item section of trinity. Anything in your bags that isn't checked as supposed to be picked up seems to get sold. Also use the DB settings to protect some of your bagspaces and keep the rift keys in those spaces so it won't sell them. When a stack of rift keys gets full transfer them to a protected tab in your stash. I don't know what causes them to be sold, but I do know you can safeguard against it by using those methods.