The first line excludes the directory - wherever it is, and thus completely ignores whatever inside that directory, so you can't even re-include it. That is why your pattern doesn't work.
In order to make this work, you must exclude the files and folders, before you can re-include them.
To make it a bit simpler, just assume one level ( removing the y-level) (I also skipped the uppercase/lowercase for clarity)
**/bin/**
x/**
!x/bin
This pattern will do exactly as you state above.
The first line excludes all content under any bin folder. The prefix ** makes it apply to any folder level, without it - it would only apply to the root level bin folder. The suffix ** makes it apply to the files and folder beneath it.
The second line explicitly excludes the 'x' folder and its content. Yes, this is weird, but is what makes this work.
Then the third line then re-includes the binary folder.
I assume you have some source code you want included under 'x', you then have the explicitly re-include that too, so good idea to place that under a separate folder.
See these posts for some of the same issues
Using .gitignore to ignore everything but specific directories
What's the difference between Git ignoring directory and directory/*?
.gitignore exclude folder but include specific subfolder