It's called an idiom. (You've used the term idiomatic, which means "having to do with an idiom." Idiom is the noun form.)
An idiom is an expression peculiar to a single language (although there may be similar ones in other languages) that has a unique meaning. We have another idiom with a similar meaning: let the cat out of the bag.
Your sentence would read like this, although I'll change it to better reflect what you're trying to say:
Secrets can be accidentally revealed, as indicated by the idiom "spilling the beans."
What I might say is:
"Spilling the beans" is an idiom that means revealing a secret that one was expected to keep.
(Spilling the beans isn't necessarily accidental.)
A friend's wife once invited me to his birthday party. I couldn't remember the time, so I called and left a message asking if they might call back and remind me. I got a call from his wife, telling me the time and that it was also to be a surprise party!! I'm glad my friend didn't hear the message, because if he had, I would have spilled the beans/let the cat out of the bag.
Here's an amusing list of idioms from a number of countries, which will show the disparity of ways that different languages use idiomatic metaphors to convey common ideas.
The article mentions a Thai idiom one afternoon in your next incarnation, meaning "never going to happen." There is quite a list of idioms for this particular idea: two English ones are when hell freezes over and when pigs fly. Others mentioned in the article are when hens have teeth (French), when a lobster whistles on top of a mountain (Russian, and my favorite), and when cows dance on the ice (Dutch).