I was tempted to speak, but I kept my mouth shut.
This is an idiom: keep one's mouth shut to mean not talk, especially not to reveal or divulge a secret or other sensitive information See the Google search for "keep one's mouth shut" define.
Since it is such a common idiom, with such a specific meaning, it can seem a little out of place if you say it to mean not to eat, even when the context is how to avoid weight gain or maintaining a good weight (that is, dieting). It's not wrong, but if English is not your native language, your use of it might send a mixed signal: is pablo using the idiomatic meaning or the literal meaning?
For example, we don't know which meaning is used in the following:
I was tempted to eat, but I kept my mouth shut.
It could mean to not talk, depending on the exact context. Even when it did, it could still be related to dieting
I was tempted to order chocolate cake for desert, but I kept my mouth shut.
The primary meaning of kept my mouth shut in the sentence above is didn't open my mouth to order chocolate cake but it also implies didn't open my mouth in order to eat the chocolate cake. It's actually a play on words.
The sentence
My strategy for avoiding weight gain is to keep my mouth shut.
suffers from the same possible double meaning. But the primary, natural meaning of the sentence is to not eat.
Therefore, how you use it, and exactly what you say regarding dieting can be problematic for the non-native speaker. If people look at you as if they don't know what you mean, you might want to explain your meaning.
Using closed is almost as problematic, since there is more than one reason to keep your mouth closed (to not talk, to not eat), but there is no idiom keep one's mouth closed.