You can gain on the scale for a number of reasons that have nothing to do with what you're eating.
For example the body holds onto and uses extra water in the healing process, so a gain on the scale can indicate that your immune system is dealing with illness or injury (even a small one like fighting off a cold you may never get or repairing muscles after a workout).
Last summer, I gained 8 lbs overnight after a painful sunburn. It wasn't diet related as I wasn't hungry and didn't overeat, but I was terribly thirsty. In a day or wo, the 8 lbs fell off as quickly as they came.
On meal replacement plans, it's pretty easy to know if you're cheating. You're either on plan or you're not, and if you're not, weight gains could be fat gains. If you are on plan, gains are most likely temporary water retention.
If you see consistent gains, despite being 100% on plan, for more than a couple weeks, you should see a doctor to rule out endocrine or other problems.