Or in any other type of container. They bug out. One day they just decide to not stack with other gold. Or not be counted, nor retrieved on the barter balance button, it says you have no money despite there being a nice stack of thousands of gold. It is possible to manually drag the gold to the barter inventory, though.
From what I can read on reddit, this is a known issue. Common fixes are stuff like dropping the money on the ground and pick it up again. Or splitting the stack to get the money out of that corrupted stack. I cant confirm any of those because I went for the fix of spending every ounce of gold, but havent had chance to check with a trader yet if my new stack of gold is uncorrupted.
I figured out you can split your corrupt gold stacks and one split of it usually uncorrupts. So now I just do that whenever I end up with corrupted gold. (For me it always happens when using the barter screen)