No, that's not random, the logic must be flawed but I am staring at the code and cannot see how.
Generally it goes something like this:
ONE: whenever item appears in your cursor
a) if it can be placed, remember it
b) otherwise, forget what you remember
TWO: whenever item disappears from your cursor
a) if you remember some item, put its ghost in the cursor
Clean cursor action has some extra logic and it prevents all of the above from happening - otherwise whenever you were putting an item down, it was getting replaced with a ghost.
There is also that mod setting "disable when gui open", but it only affects case TWO (when item disappears from your cursor) - prevents it from happening. In your case it sounds like the remembered item is wrong, or rather the item should have been remembered but it wasn't. Anyway, do you have this option selected?
In regards to "Pick ghost item if no items are available" from Settings / Interface, this is only used whenever you click an item on the tool belt. I have it selected too.